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?

  • have you tried to add esc_attr to $m, like return esc_attr( $m );? Commented Jan 23, 2013 at 10:08

2 Answers 2


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.']');


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.

  • 2
    echo "<pre>"; var_dump($varName); exit; will make it easily visible on the page.
    – Kayo
    Commented Mar 28, 2013 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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