WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having a problem here:

I am passing this through a custom field: http://www.youtube.com/watch?v=E6P1Q-UycHA&autoplay=1

(notice the autoplay=1)

But when I load the video on my theme using wp_oembed_get... it displays the video fine, but it does not listen to the autoplay=1 variable I am passing through.

I need the videos to play on the load of the page.

Any ideas?

Thanks, Alain Fontaine

share|improve this question
Try This Answer: stackoverflow.com/a/16801334/2721050 That was very helpful for me – Erez Lieberman Feb 22 '15 at 13:26

Those are not really arguments like for YouTube, more of arguments for WordPress itself.

One way to handle it would be to access your argument later inside of a filter and modify HTML output.

Pass in arguments array:

wp_oembed_get( 'http://www.youtube.com/watch?v=', array( 'autoplay' => 1 ) );

And filter:

add_filter('oembed_result','oembed_result', 10, 3);

function oembed_result($html, $url, $args) {

    // $args includes custom argument
    // modify $html as you need

    return $html;
share|improve this answer

I know this question is pretty old, but I have a working solution that I figure might be helpful to anyone else trying to find this info and coming up empty in Google searches.

This solution has been tested in WordPress 3.7.1+:

 * Adds the `autoplay` query string argument to embedded YouTube videos
function wpse5362_autoplay_youtube_oembed( $provider, $url, $args ) {
    if (strpos($provider, 'youtube')!==FALSE) {
        $provider = add_query_arg('autoplay', 1, $provider);

    return $provider;
add_filter('oembed_fetch_url', 'wpse5362_autoplay_youtube_oembed', 10, 3);

Add the above in your theme's functions.php to cause all YouTube videos added via oEmbed to autoplay.

How This Works

In class-oembed.php on line 212, the fetch() method applies the filter oembed_fetch_url to allow modifications to the URL.

To avoid adding useless parameters to other oEmbed providers, we check for "youtube" in the provider URL — we could also check for "vimeo" and/or other video services — and, if that string is present, adds an autoplay argument to the query string.

share|improve this answer

This is my solution in functions.php

function embed_responsive_autoplay($code){
    if(strpos($code, 'youtu.be') !== false || strpos($code, 'youtube.com') !== false){
        $return = preg_replace('@embed/([^"&]*)@', 'embed/$1&showinfo=0&autoplay=1', $code);
        return '<div class="embed-container">' . $return . '</div>';
    return '<div class="embed-container">' . $code . '</div>';

add_filter( 'embed_oembed_html', 'embed_responsive_autoplay');
add_filter( 'video_embed_html', 'embed_responsive_autoplay' ); // Jetpack


share|improve this answer
Please don't dump a code block, perhaps edit and add some explanation to it. – Mayeenul Islam Dec 13 '14 at 5:01
First code that I have tested that works. Thanks. – Olen Jun 2 at 5:30

Anything after the first parameter must be sent as an array of arguments.

See the example given on the codex page.

If you're attempting to take a custom field value and have the embed code convert it into a video(ie. what would happen if you placed it into the content), then you can do something like this...

   N - replace with a valid post ID
   key - replace with a valid custom field key(name)
$data = get_post_meta( N, 'key', true );
if( $data )
   echo apply_filters( 'the_content', $data );

This of course will run several filters over the data that you don't need, but it does the trick all the same..

share|improve this answer
Unfortunately, the only arguments that wp_oembed_get will listen to are 'width' and 'height' – John P Bloch Dec 14 '10 at 21:00
Guess there's no passing in that arg then.. at least not using wp_oembed_get .. – t31os Dec 14 '10 at 21:10
Yeah; as far as I know (although I could be wrong about this) youtube's oEmbed API doesn't allow for that argument at all. – John P Bloch Dec 14 '10 at 21:56
I did a little digging into the embed, and as far as i can tell(like you said) the only args that get passed along are height and width.. (easy to test, call the func with an array passed in, doesn't work with autoplay, width and height work though). – t31os Dec 14 '10 at 22:05
Thanks everyone, I will have to look into another solution. – criticerz Dec 15 '10 at 4:44

This can be easily fixed by modifying the wp_oembed_get() function in wp-includes/media.php to this:

function wp_oembed_get( $url, $args = '' ) {
    // Manually build the IFRAME embed with the related videos option disabled and autoplay turned on
    if(preg_match("/youtube.com\/watch\?v=([^&]+)/i", $url, $aMatch)){
        return '<iframe width="560" height="315" src="http://www.youtube.com/embed/' . $aMatch[1] . '?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';

    require_once( ABSPATH . WPINC . '/class-oembed.php' );
    $oembed = _wp_oembed_get_object();
    return $oembed->get_html( $url, $args );
share|improve this answer
Also, be sure to run the following SQL query after you make this change so that the embed is refreshed: DELETE FROM wp_postmeta WHERE meta_key LIKE '_oembed_%' – interimpulso Apr 12 '12 at 7:38
You cannot update WP anymore after you doing this. Not recommended. – toscho Apr 13 '12 at 1:32
Modifying core is just a bad idea. – manifestphil Apr 1 '13 at 17:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.