How To Modify YouTube oEmbed URLs In WordPress?

With oEmbed you can automatically embed any YouTube video simply by pasting its URL in post content. Unlike to default iframe embed code, oEmbed is easy, responsive but there are no visual options to reset custom values such as hiding YouTube logo, show info etc.

In this lesson you will learn about assigning custom parameters to YouTube video oEmbeds in WordPress.

By using the following function in your theme’s functions.php file you can implement custom oEmbed parameters on all YouTube videos embedded in your WordPress site.

function custom_youtube_settings($code){

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

add_filter(’embed_handler_html’, ‘custom_youtube_settings’);
add_filter(’embed_oembed_html’, ‘custom_youtube_settings’);

In the given code, there are certain parameters which you can customize or add more parameters seperated by ‘&’ as shown in the above given code.

To play video in High Def use: HD=1To hide related videos use: rel=0To remove YouTube control bar use: controls=0To remove frame and border use: frameborder=0 and To hide video title use: showinfo=0.

For online support email to system@sangkrit.net or download Personal App of System Administrator.

Leave a Reply