Any way to use a custom Parameter for youtube embed without using an iframe?

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?

Read More

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);

?>

Related posts

Leave a Reply

3 comments

  1. No need for a plugin, You can simply use the Oembed class’s oembed_result filter hook

    like this:

    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);
    

    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.

  2. 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:

    /**
     * Add Custom Parameters to YouTube Embeds
     */
    function namespace_oembed_youtube_no_title( $html, $url, $args ) {
    
        // Only run this for YouTube embeds
        if ( !strstr($url, 'youtube.com') )
            return $html;
    
        // Get embed URL
        $url_string = parse_url($url, PHP_URL_QUERY);
        parse_str($url_string, $id);
    
        // Set default arguments
        $defaults = array(
            'width' => 480,
            'height' => 385,
            'showinfo' => true,
            'rel' => true
        );
    
        // Merge args with defaults
        $args = wp_parse_args( $args, $defaults );
    
        // Define variables
        extract( $args, EXTR_SKIP );
    
        // Add custom parameter values to IFRAME
        if ( isset($id['v']) ) {
            return '<iframe width="' . intval($width) . '" height="' . intval($height) . '" src="http://www.youtube.com/embed/' . $id['v'] . '?rel=' . intval($rel) . '&showinfo=' . intval($showinfo) . '" frameborder="0" allowfullscreen></iframe>';
        }
    
        return $html;
    }
    add_filter('oembed_result', 'namespace_oembed_youtube_no_title', 10, 3);
    

    And now for the wp_oembed_get() call:

    // oEmbed Video
    $video = wp_oembed_get('http://www.youtube.com/watch?v=mx4xeO3Xq7g', array(
        'width' => 632,
        'height' => 474,
        'showinfo' => false,
        'rel' => false
    ) );
    

    Thanks again for adding this solution, the original post solved an issue for me and was really helpful.

  3. 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.