Enabling shortcodes for custom fields

Normally WordPress does not run shortcode that you put into a custom field.

By default, Custom Fields display whatever value you enter, as plain-text, so if you try entering a shortcode, (in the format [shortcode] VALUE [/shortcode]) you’ll end up displaying the entire text, including the tags.

Add the following in your template file, it can be single.php or page.php:

echo apply_filters('the_content', get_post_meta($post->ID,'YOUR_CUSTOM_FIELD_NAME', true));

or…

$shortcode = get_post_meta($post->ID,'YOUR_CUSTOM_FIELD_NAME',true);
echo do_shortcode($shortcode); 

Leave a Comment