0

The hardcoded HTML looks like this →

    <iframe width="560" height="315" src="https://www.youtube.com/embed/G4Q0oX8wquU" allow="autoplay; 
encrypted-media" allowfullscreen></iframe>   

But in the case of the WordPress, it should come from the meta - The URL that is saved in Oembed.

Look at this image of the single.php backend →

enter image description here

I tried something of this sort:

<?php 
   $url = esc_url( get_post_meta( get_the_ID(), 'video_oembed', 1 ) ); 
   echo wp_oembed_get( $url );
?>

More precisely like this →

<iframe width="560" height="315" src="<?php 
       $url = esc_url( get_post_meta( get_the_ID(), 'video_oembed', 1 ) ); 
       echo wp_oembed_get( $url );
    ?>" allow="autoplay; encrypted-media" allowfullscreen></iframe>

But nothing actually worked. Please help me to understand the logical gap.

Extra Information → Currently, a Loop is running that fetches posts that have video URL in the Oembed.

Loop is running like this.

The live page is here.

Currently, the Video is hardcoded, but the idea is as soon as one clicks on the image of the post thumbnail just below the hard-coded HTML video framework. the oEmbed Video URL should come with Iframe. By default the Oemebed Video I frame should come of the latest post fetched.

0

wp_oembed_get() returns the whole iframe, that's its purpose. So you should use it on its own, not in the src of an iframe.

$url = esc_url( get_post_meta( get_the_ID(), 'video_oembed', 1 ) ); 
echo wp_oembed_get( $url );
  • But I think that this will work only in the WP Loop not outside the loop in single.php? – The WP Novice May 30 '18 at 3:32
  • That’s got nothing to do with wp_oembed_get(). Only thing the loop would affect is how you get the meta value to use in it. – Jacob Peattie May 30 '18 at 3:39
  • Hi, I have updated the question. – The WP Novice May 30 '18 at 9:23
  • wp_oembed_get() takes a URL and returns the oembed output for it. Typically an iframe. In terms of getting that URL from post meta? That's completely unrelated and depends entirely on how the field was originally added. Since WordPress does not have an oEmbed field in core you will need to consult the documentation for the theme/plugin that added the cutsom field for the URL. – Jacob Peattie May 30 '18 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.