I need to add video from youtube in certain place on my page. I added link in post like https://www.youtube.com/watch?v=GXGR7puGRpg (post contains only this link), and then I added code on my page

$post_id_63 = get_post( $post_id = 63 );
if($post_id_63) {
    $post_id_63_content = $post_id_63->post_content;
    echo $post_id_63_content;

but I get just text link on my page, not video. What did I do wrong? How to fix it and make it work ?

1 Answer 1


This is overview how you can make it working:

First with below code you can detect youtube URL for details Please read:

$reg = preg_match('|^\s*(https?://[^\s"]+)\s*$|im', $post_id_63->post_content, $matches);

 if (!$reg) return false;

 $url =  trim($matches[0]); // youtube video url 

 echo wp_oembed_get($url); // this will return youtube vidoe 

For details please read: Wp_oembed_get

we need to use wp_oembed_get to make URL into video from post content


  • I am glad that it makes some sense :)
    – jas
    Dec 2, 2015 at 8:27

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.