S. Fellig
S. Fellig

Reputation: 275

Shortcodes and Custom Fields

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:

http://i.imgur.com/41vsr.png

Upvotes: 0

Views: 1065

Answers (1)

The Alpha
The Alpha

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

Related Questions