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?
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 asked Oct 17, 2012 at 0:20 PizaulPizaul 315 bronze badges 1 |2 Answers
Reset to default 2Make 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.
esc_attr
to$m
, likereturn esc_attr( $m );
? – Mike Madern Commented Jan 23, 2013 at 10:08