Post Pic

How to execute shortcodes inside custom fields

By default, WordPress do not allows shortcodes to be executed inside custom fields. If for some reason you need to be able to execute a shortcode inside a specific custom field, here is an easy way to do it.

Just put this code into whatever page you are displaying the results of the shortcode, and change the your_custom_field_here to the name of your custom field.

<?php echo apply_filters('the_content', get_post_meta($post->ID, 'your_custom_field_here', true)); ?>

Credit: Snipplr.

5 Responses

Jul 18 2012 20:32

Why not just ID, ‘your_custom_field_here’, true)’); ?>

Jul 18 2012 20:34

Since my last comment got partially eaten, why not just use do_shortcode() ?

Jul 26 2012 21:23

Many thanks, it worked like charm :)

Aug 03 2012 10:08

very good. thanks for sharing this. it worked.

Dec 29 2012 12:54

Why use apply_filters beside do_shortcode function?

ID, ‘cfield’, true) )
echo do_shortcode(get_post_meta($post->ID, ‘cfield’, $single = true));
?>

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox