I do not want to display the titles of videos I embed on my wordpress site. The way I’ve been doing this is using the embed link, inserting the iframe in the wordpress post and adding the custom Parameter “showinfo=0” to the end of the url. This has worked well, until I decided to change the design of my site. I have had to use some custom css to change all the videos (almost 200) that I’ve done that to in order to fit the new design. If I would have known of a way just to drop the link into wordpress (like most people do) I wouldn’t have had to use an iframe and wordpress would have adjusted the size of the video based on the setting entered in the media section.
I’m hoping there is a better way to embed a Youtube video than the way I’ve been doing it (It would be great to just drop the link into wordpress instead of having to go through so many different steps in order to get the video to show up. Does anyone have any ideas how (of if it’s even possible) to do this?
I post a video every day, so it would really help my process if there was a way to do this. Thanks.
`
<?php
load_theme_textdomain('standardtheme', get_template_directory() . '/lang');
$locale = get_locale();
$locale_file = get_template_directory() . '/languages/$locale.php';
if(is_readable($locale_file)):
require_once($locale_file);
endif;
add_theme_support('post-thumbnails');
require_once('admin/functions.php');
require_once('lib/standardtheme.php');
require_once('lib/pro-photo/pro-photo.php');
function Oembed_youtube_no_title($html,$url,$args){
$url_string = parse_url($url, PHP_URL_QUERY);
parse_str($url_string, $id);
if (isset($id['v'])) {
return '<iframe width="'.$args['width'].'" height="'.$args['height'].'" src="http://www.youtube.com/embed/'.$id['v'].'?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>';
}
return $html;
}
add_filter('oembed_result','Oembed_youtube_no_title',10,3);
?>
No need for a plugin, You can simply use the Oembed class’s
oembed_result
filter hooklike this:
so just paste this code in your theme’s functions.php file, setup the width and height at the settings >> media panel and you should be just fine with simply pasting the youtube’s video url in the post.
Great solution Bainternet,
A quick addition to it, it may be a good idea to first check that the embed is a YouTube embed before replacing those values so that you don’t break other embed types. It’s also handy to use the WordPress pattern for parsing arguments with defaults. Based on these two additions, here’s a modified function (where “namespace” is your namespace:
And now for the
wp_oembed_get()
call:Thanks again for adding this solution, the original post solved an issue for me and was really helpful.
Just grab the URL, add your query string, and let WordPress’ built-in oEmbed support handle it.
That is: pull the URL out of the iframe embed code, and then append
&showinfo=0
to the end of it. Paste the result into the post content on its own line, and voila: WordPress will embed the video properly, with no title displayed.Here’s a working example:
http://www.youtube.com/v/GrfGGzRNC4U?version=3&hl=en_US&showinfo=0
I pulled that URL from the embed code, not the shortened URL.