Ask your WordPress questions! Pay money and get answers fast! (more info)

Enable a short code in the custom meta field

  • SOLVED

I was wondering if there is a filter that allows me to enable short codes to work inside the custom meta fields in my posts.

I know the following code enables it in widgets:

add_filter('widget_text', 'do_shortcode');

And where would I have to put a code? My theme has shortcodes.php also meta-boxes.php

P.S I've asked this question on stackexchange.com

[[LINK href="null"]]http://wordpress.stackexchange.com/questions/163518/enable-a-short-code-in-the-custom-meta-field[[/LINK]]

And I also found some similar question here:

https://wordpress.org/support/topic/allowing-shortcode-in-custom-fields

But I can't figure out where to put these codes that they are offering? I've called my custom field "best" (without quotes). So if what they say is true the code I need to use should look like this echo <?php do_shortcode( get_post_meta($post->ID, 'best', true) ); ?>

Answers (4)

2014-10-07

Bob answers:

This thing depends on where you want to use metabox in your theme files.

you can use either use
<?php echo do_shortcode( get_post_meta($post->ID, 'best', true) ); ?>

or

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


Jmantis comments:

I've tried to insert both codes in to my custom field before the short code, but here is what I can see now (see image attached)

Any ideas what I could have done wrong?