I've a custom post type "video" and wanted to show videos like youtube, dailymotion in a specified area using WP default oembed script. So i'm using a custom field"video url", but the problem is that oembed work in the_content not with custom field. so how can i do this. or any other solution
If the custom field only contains the video URL like http://www.youtube.com/watch?v=dQw4w9WgXcQ
, then you can get the oEmbed HTML code with wp_oembed_get:
$videourl = 'http://www.youtube.com/watch?v=dQw4w9WgXcQ';
$htmlcode = wp_oembed_get($videourl);
echo $htmlcode;
If your custom field contains more than just the URL, you could use the the_content
filter to do the same thing the the_content
-function does:
$content = "<h2>this video is great</h2>\n<p>check it out</p>\n"
. "[embed]http://www.youtube.com/watch?v=dQw4w9WgXcQ[/embed]";
$htmlcode = apply_filters('the_content', $content);
echo $htmlcode;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With