• Hi there,

    I want to add these youtube parameters ?rel=0&?wmode=transparent&iv_load_policy=3&showinfo=0&vq=hd1080 to the youtube iframe that is created with the oembed function. For Example: pasting a youtube link (http://www.youtube.com/watch?v=-McFIAlP0Ow) inside a post will now only result in this:

    <iframe width="100%" height="394" src="http://www.youtube.com/embed/-McFIAlP0Ow?feature=oembed" frameborder="0" allowfullscreen="" style="height: 420px;"></iframe>

    I want the oembed function to automatically add the earlier mentioned parameters, so the iframe will look like this:

    <iframe width="100%" height="394" src="http://www.youtube.com/embed/-McFIAlP0Ow?feature=oembed?rel=0&?wmode=transparent&iv_load_policy=3&showinfo=0&vq=hd1080" frameborder="0" allowfullscreen="" style="height: 420px;"></iframe>

    I know i can add these parameters manually by adding them to the iframe html code provided by youtube. But i have a lot of bloggers and want to make it as simple as possible for them to create youtube posts. So rather then let them use the youtube iframe code i want them to just paste the youtube link inside the posts and let oembed do all the work for them.

    I already know the oembed functions are located in wp-includes/class-oembed.php, but my lack of javascript and php skills stops me from randomly adding coding to this file.

    I really hope someone can provide me with the right piece of php coding or javascript!

    Thanks and Merry Christmas to all of you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    Hook the ‘oembed_result’ filter and use PHP string functions to insert the required parameters in the passed iframe HTML, then return the result.

    Thanks for the feedback, but I really lack PHP skills. Could you provide me with the right code?

    Moderator bcworkz

    (@bcworkz)

    The basic code frame work looks like the following. It’s untested, the string replacement details may need to be tweaked to get the correct results. This would go on your theme’s functions.php file.

    add_filter('oembed_result', 'r1k_fix_oembed')
    function r1k_fix_oembed( $embed ) {
       return str_replace('?feature=oembed', '?feature=oembed&rel=0&?wmode=transparent&iv_load_policy=3&showinfo=0&vq=hd1080', $embed );
    }

    Thanks bcworkz,

    I’ve added to code to the theme’s functions.php but it will break the website. Do you have any suggestions what part of the code needs to be tweaked?

    bcworkz, i’ve managed to modify a piece of coding that was posted by someone else in a similar thread 2 years ago.

    to make it work i used 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="100%" height="394" src="http://www.youtube.com/embed/'.$id['v'].'?rel=0&?wmode=transparent&iv_load_policy=3&showinfo=0&vq=hd1080" frameborder="0" allowfullscreen></iframe>';
        }
        return $html;
    }
    add_filter('oembed_result','Oembed_youtube_no_title',10,3);

    I don’t know if this is still an issue but I just bumped into it and, after nothing worked, I cast further online. I found this post and added the code to my theme’s functions.php resolved the issue for all videos posted at the site.

    http://tutorialshares.com/youtube-oembed-urls-remove-showinfo/

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Help needed: Adding YouTube parameters to oEmbed function’ is closed to new replies.