I’m using the code below to set the width and height of youtube embeded links
//////////////////////////////////////////////////////////////////
// Youtube shortcode
//////////////////////////////////////////////////////////////////
add_shortcode('youtube', 'shortcode_youtube');
function shortcode_youtube($atts) {
$atts = shortcode_atts(
array(
'id' => '',
'width' => 845,
'height' => 500
), $atts);
return '<div class="video-shortcode"><iframe title="YouTube video player" width="' . $atts['width'] . '" height="' . $atts['height'] . '" src="http://www.youtube.com/embed/' . $atts['id'] . '" frameborder="0" allowfullscreen></iframe></div>';
}
For example, I will place this link –> https://youtu.be/YQHsXMglC9A
, in the post and it automatically embeds.
The code above isn’t rendering the width and height. I also tried the code below.
add_filter( 'embed_defaults', 'change_embed_size' );
function change_embed_size() {
// Adjust values
return array('width' => 800, 'height' => 500);
}
That didn’t work either. Also that code seems like it targets all embeds on the site I want it to specifically target youtube.
Is there another option or way to make any of these work.