4.0Essential Grid 4.0 is here — see what’s new

FAQ

Add Custom Meta to Page or Post via Shortcode

Essential Grid 3 · The 4.0 FAQ

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];

    }

}