• Resolved guillaumemolter

    (@guillaumemolter)


    Hi,

    I would like to enable the js api to embeded youtube vidéos.

    Youtube’s documentation states that you have to add enablejsapi=1 at the end of your src url.

    So I’m trying to find a filter that would allow me to automatically append it to generated iframes when you copy paste a Youtube url in the editor.

    I’ve been looking into wp_embed_handler_video and embed_defaults but I’m really sure what I’m supposed to do.

    Does anyone as an idea? Or at least tell me where to look in the codex?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Jon (Kenshino)

    (@kenshino)

    Lord Jon

    If you’re using oembed, try the code below

    function youtube_enable_js_api( $html, $url, $args ) {
    
        /* Modify video parameters. */
        if ( strstr( $html,'youtube.com/' ) ) {
            $html = str_replace( '?feature=oembed', '?feature=oembed&enablejsapi=1', $html );
        }
    
        return $html;
    }
    add_filter( 'oembed_result', 'youtube_enable_js_api', 10, 3 );
    Thread Starter guillaumemolter

    (@guillaumemolter)

    Indeed! Exactly what I needed! Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding extra parameters to auto embeded Youtube urls’ is closed to new replies.