1

How can i put a youtube video on my post without show the default title from youtube?

I tried to put this code in the theme´s functions, but not worked.

function remove_youtube_controls($code){
    if(strpos($code, 'youtu.be') !== false || strpos($code, 'youtube.com') !== false){
        $return = preg_replace("@src=(['\"])?([^'\">s]*)@", "src=$1$2&showinfo=0&rel=0", $code);
        return $return;
    }
    return $code;
}

add_filter('embed_handler_html', 'remove_youtube_controls');
add_filter('embed_oembed_html', 'remove_youtube_controls');

Someone can help?

Thanks

  • you need to update $return = preg_replace("@src=(['\"])?([^'\">s]*)@", "src=$1$2&showinfo=0&rel=0", $code); to ` $return = preg_replace("@src=(['\"])?([^'\">]*)@", "src=$1$2&showinfo=0&rel=0", $code);` – Bikash Waiba Jun 10 '17 at 22:42
  • you have extra ` s ` in preg_replace – Bikash Waiba Jun 10 '17 at 22:48
-1

Update: Try this one.. it works for youtube url in your post which is converted to iframe by wordpress.

   function remove_youtube_controls($code){
    if(strpos($code, 'youtu.be') !== false || strpos($code, 'youtube.com') !== false){
        $return = preg_replace("@src=(['\"])?([^'\">]*)@", "src=$1$2&showinfo=0&rel=0", $code);
        return $return;
    }
    return $code;
}

add_filter('embed_handler_html', 'remove_youtube_controls');
add_filter('embed_oembed_html', 'remove_youtube_controls');
  • 1
    where do you place it, and frankly, since youtube embeds are iframes, why should it work at all? – Mark Kaplun Jun 10 '17 at 19:42
  • Doesn't work, it's an iframe. I just tried it even though I knew it wouldn't work. When you see that class, it's part of the iframe's html, not the site's html. – Christina Jun 10 '17 at 20:46
  • I changed the code hope it works. – Bikash Waiba Jun 10 '17 at 22:32
1

This works, the OP code was odd and I've never seen that usage before or the other filter. Tested and works. This code removes Title on youtube but doesn't touch anything else since the parameters wouldn't be relevant on Vimeo for example.

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

    if( strpos( $url, 'youtu.be' ) !== false || strpos( $url, 'youtube.com' ) !== false ) :

        return str_replace( '?feature=oembed', '?feature=oembed&showinfo=0&rel=0', $html );

    else:

        return $html;

    endif;

}
add_filter( 'embed_oembed_html', 'yourprefix_remove_title_youtube_oembed', 10, 3 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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