0

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

Thanks in advance.

1

You could try running the content of the custom field through the do_shortcode() function when you output. e.g. given a custom field name of 'custom field'

echo do_shortcode( get_post_meta($post->ID, 'custom-field', true) );
  • Thanks @nothingtosee, but there would I have to add this code? Functions.php or somewhere else? – Mantas Oct 6 '14 at 5:03
  • Anywhere you intend to output (i.e. in the theme templates) – nothingtosee Oct 6 '14 at 5:20
  • sorry I just want to make sure my code is right before I put it in: <?php echo do_shortcode( get_post_meta($post->ID, 'Price Check:', true) ); ?> – Mantas Oct 6 '14 at 19:52
  • As long as your custom field key is 'Price Check:' then yep. – nothingtosee Oct 7 '14 at 8:36
  • thanks, but I still can't get it work – Mantas Oct 7 '14 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.