Why isn’t this youtube shortcode working?

echo do_shortcode('https://www.youtube.com/watch?v=vZBCTc9zHtI');

Is merely printing

https://www.youtube.com/watch?v=vZBCTc9zHtI" 

out onto the page.

I know I can display the video with html with

<iframe src="https://www.youtube.com/embed/vZBCTc9zHtI" width="560" height="315" frameborder="0" allowfullscreen></iframe>

but I’m trying to leverage wordpress’ built-in methods. How do I do this?

4 Answers
4

I think this is what you are looking for:

<?php echo wp_oembed_get('https://www.youtube.com/watch?v=vZBCTc9zHtI'); ?>

For more details check this documentation.

Leave a Comment