When I try to embed a YouTube video using one of the following ways:

  • By entering a YouTube URL
  • By entering an [embed] shortcode
  • By adding a video through the media browser (which results in an [embed] shortcode)

I am seeing the video just fine in the editor view:

enter image description here

But in the frontend view, using this code:

 $content_desktop = do_shortcode(get_the_content());

I am seeing

  • when entering a pure URL: the unparsed URL enter image description here

  • When entering an [embed] shortcode or using the WYSIWYG editor: literally nothing enter image description here

Things I've checked:

  • I'm the admin user so there should be no problems with rights
  • Other shortcodes work fine
  • The DOM literally shows what I show above, there is no CSS interference
  • The YouTube videos I'm trying to embed allow external embedding
  • There are no options for me to check in "Settings" > "Media" (apparently it used to be that you had to explicitly turn on media embedding there, but no more)

Is there something well known that could be causing this?

  • What does show up in the source? What's in the DOM? Your embeds could be hidden by CSS and/or JavaScript.
    – janh
    Commented Jan 28, 2018 at 11:42
  • @janh nope, the DOM contains the YouTube URL in the first case and literally nothing in the second. I do have a fair amount of plugins running, but none that should/would obviously influence media embeds...
    – Pekka
    Commented Jan 28, 2018 at 11:58

1 Answer 1


I've just looked at the source of the WP_Embed class, and it appears they are not actually registering a shortcode, but hooking into the the_content filter.

Change your code to

$content_desktop = apply_filters("the_content", get_the_content());

or manually trigger their filter with something like

$content_desktop = WP_Embed::run_shortcode(get_the_content());

or, if you prefer to have an object:

$myembeds = new WP_Embed;
$content_desktop = $myembeds->run_shortcode(get_the_content());

See also WP_Embed::run_shortcode in the codex, and the source code of class-wp-embed.php.

  • 1
    Argh! I had no idea! Running WP_Embed::run_shortcode() doesn't seem to work, but apply_filters() does. Thank you!
    – Pekka
    Commented Jan 28, 2018 at 17:45

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.