Add Custom Meta to Page or Post via Shortcode

The following example shows how you can add the grid’s Custom Meta content to the page via shortcode. This is useful if you want to make editing content easy for your client.

1. Create the Custom Meta

2. Add some content to the new Custom Meta field

3. Add the following shortcode to the page, and modify the “eg-my-custom-meta” part to whatever handle was chosen for the Custom Meta previously created.

[grid_meta key=”eg-my-custom-meta”] 

4. Add the following code to your theme’s “functions.php” file

add_shortcode('grid_meta', 'print_grid_meta');
 
function print_grid_meta($atts) {
 
    global $post;
    $meta = get_post_meta($post->ID);
 
    extract(shortcode_atts(array('key' => ''), $atts));
 
    if($key && array_key_exists($key, $meta)) {
 
        return $meta[$key][0];
 
    }
 
}
 
Add Custom Meta to Page or Post via Shortcode

The Author

KC

Strength does not come from winning. Your struggles develop your strengths. When you go through hardships and decide not to surrender, that is strength.

Liked this Post?
Please Share it!

[tp_popular title="Popular Grids" regex="(grids|template_library)" count=3]

Newsletter

Join over 25.000 others on the Essential Grid and Slider Revolution email list to get access to the latest news and exclusive content.