Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm developing a plugin, wherein one of the features is to switch out forms on a specific page by changing the shortcode within a custom field.

within my plugin file:

function getShort()
{
    global $post;
    $m = get_post_meta($post->ID, 'short', true);
    return $m;
}

within my theme file:

$short = getShort();
echo do_shortcode($short);

With the code above, it just prints out the shortcode. If I echo the value of $short, copy and paste that as the argument for do_shortcode(), it prints out the expected value.

I am 100% confident that the value of $short is a string, and is the correctly formatted shortcode. Any idea why this doesn't work?

share|improve this question
    
have you tried to add esc_attr to $m, like return esc_attr( $m );? –  Mike Madern Jan 23 '13 at 10:08

2 Answers 2

Even though you're confident that this isn't the case, it sounds as if the value you are passing manually is not the same as the value in $short.

Dump the contents of $short (var_dump($short);) and have a look the source of the genereated page! There's a good chance that the variable contains tags or other chars that won't be visible in the rendered browser view.

share|improve this answer
2  
echo "<pre>"; var_dump($varName); exit; will make it easily visible on the page. –  Kayo Mar 28 '13 at 9:55

Make sure that the string in $short variable is between square brakets, like [header]. If it's not stored that way, make the call like this echo do_shortcode('['.$short.']');

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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