Reputation: 275
How do I get shortcodes to process properly in custom fields?
I've tried using the code below, but I cannot figure out where to place it ("button" is the name of the field):
<?php
if ( get_post_meta($post->ID, 'button', true) )
echo do_shortcode(get_post_meta($post->ID, 'button', $single = true));
?>
As of now, the shortcode is working in the sense that the button is displaying, but the shortcode text is displaying where the "buy now" button is supposed to be. See screenshot:
Upvotes: 0
Views: 1065
Reputation: 146201
Just put this code into whatever page you are displaying the results of the shortcode.
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'button', true)); ?>
Update: Place it inside the loop
if ( get_post_meta($post->ID, 'button', true) )
echo do_shortcode(get_post_meta($post->ID, 'button', $single = true));
Upvotes: 1