TransWikia.com

Replace youtube embed in wordpress

WordPress Development Asked on November 28, 2021

I am using this code to replace youtube video:

add_filter('embed_oembed_html', 'foo_embed_oembed_html', 99, 4);
add_filter('video_embed_html', 'foo_embed_oembed_html');

function foo_embed_oembed_html( $cache, $url, $attr, $post_ID ) {

    if ( false !== strpos( $url, 'youtube' ) ) {
    
        if ( preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v/)[^&n]+(?=?)|(?<=v=)[^&n]+|(?<=youtu.be/)[^&n]+#", $url, $matches)) {

               // return my shortcode

        }
}

This works well with this example:

https://www.youtube.com/embed/LPVKH11pA8s

But the function foo_embed_oembed_html is not even called if I use this:

https://www.youtube.com/embed/LPVKH11pA8s?rel=0

What would be the reason?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP