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.



3 Answers 3


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.

  • That worked as well
    – Jordash
    Commented Jul 18, 2011 at 18:02
  • 1
    @Jordash yeah, it's essentially same solution, I just wanted to give more details why exactly it doesn't work in regular way.
    – Rarst
    Commented Jul 18, 2011 at 18:22
  • I couldn't manage to make this work in Wordpress 3.6.
    – Cthulhu
    Commented Aug 29, 2013 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;
  • Yeah that worked
    – Jordash
    Commented Jul 18, 2011 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;
  • 4
    Please add an explanation to your answer: why could that solve the problem?
    – fuxia
    Commented Jul 14, 2013 at 11:51

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.