How to fix Embed and YouTube Responsive in WordPress?

How to fix Embed and YouTube Responsive in WordPress?

There are some codes that you have to place in your functions.php to fix Embed and YouTube Responsive.

To enable Embed you have to place this Code

add_filter('embed_oembed_html', function($code) {
	return str_replace('<iframe', '<iframe class="embed-responsive-item"  ', $code);
});

For Responsive YouTube Video Place this Code

add_filter('embed_oembed_html', function ($html, $url, $attr, $post_id) {
	if(strpos($html, 'youtube.com') !== false || strpos($html, 'youtu.be') !== false){
		return '<div class="embed-responsive  embed-responsive-16by9">' . $html . '</div>';
	} else {
		return $html;
	}
}, 10, 4);

For Responsive Iframe try this Code

add_filter('the_content', function($content) {
	return str_replace(array("<iframe", "</iframe>"), array('<div class="iframe-container"><iframe', "</iframe></div>"), $content);
});




Copyright © 2020-2021 Engineer Jagat All rights reserved. Developed by Ravindra Rana