WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use Custom Field types to embed Youtube videos in a more organized fashion and using the Do_Shortcode() would seem to work perfectly, however this:

<?php echo do_shortcode('[embed]http://www.youtube.com/watch?v=K0M09Ws8vpc&feature=player_embedded[/embed]'); ?>

Does not seem to work, however in the same single.php file this does work perfectly:

<?php echo do_shortcode('[gallery link="file" size="thumbnail" icontag="div"]'); ?>

I put them one after another to test them out, any ideas why the [embed] shortcode doesn't get parsed (it just shows nothing)

If I do the embed shortcode directly into the post it works perfectly.



share|improve this question

Simply put [embed] is not a regular shortcode. Most of the time it does nothing. What happens when post content goes through the_content filter is following:

  1. [emded] is currently registered to do nothing ( __return_false() )

  2. WP_Embed->run_shortcode() filter runs with low 8 priority

  3. all shortcodes are disabled
  4. [embed] is registered to WP_Embed->shortocde()
  5. do_shortcode() executes on content (only doing embeds, since rest is disabled)
  6. shortcodes are restored to original state, [embed] is back to being useless.

So my quick guess for something to try would be:

global $wp_embed;

echo $wp_embed->run_shortcode('[embed]whatever[/embed]');

But note that there is also caching involved (embedding results are saved to custom field of the post, otherwise it would need to make HTTP request every time) and you are likely breaking that, unless you are doing it inside loop and close to where it normally works. Maybe even then.

share|improve this answer
That worked as well – Jordash Jul 18 '11 at 18:02
@Jordash yeah, it's essentially same solution, I just wanted to give more details why exactly it doesn't work in regular way. – Rarst Jul 18 '11 at 18:22
I couldn't manage to make this work in Wordpress 3.6. – Cthulhu Aug 29 '13 at 9:13

Your code should work, possibly an idea for a trac ticket.

In the meantime you can try:

global $wp_embed;
$post_embed = $wp_embed->run_shortcode('[embed]http://www.youtube.com/watch?v=K0M09Ws8vpc&feature=player_embedded[/embed]');
echo $post_embed;
share|improve this answer
Yeah that worked – Jordash Jul 18 '11 at 18:02
   $video_url = get_post_meta($post_id, 'video_url',true);
    $video_url .= 'video url';
    $check_embeds=$GLOBALS['wp_embed']->run_shortcode( '[embed]'. $video_url .'[/embed]' );
    echo $check_embeds;
share|improve this answer
Please add an explanation to your answer: why could that solve the problem? – toscho Jul 14 '13 at 11:51

Your Answer


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.