How to use WP oembed script outside the_content

I have a custom message like "video" and you want to show videos like youtube, dailymotion in the specified area using the WP default oembed script. Therefore, I use the custom field "video URL", but the problem is that oembed does not work with the custom field in the_content . so how can i do that. or any other solution

+5
source share
2 answers

If the custom field contains only the video URL, for example http://www.youtube.com/watch?v=dQw4w9WgXcQ, 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;

, URL-, the_content the_content:

$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;
+11

. , wp_oembed_get, . , video_url .

, video_url , oMmbeds .

<?php if (!((get('video_url', TRUE))=='')) {
    echo wp_oembed_get( get('video_url', true) );
}?>
-1

All Articles