WordPress YouTube native responsive

The native YouTube url when you embed into wordpress content is not responsive so we need to add a code to this iframe or embed

so we need to add to functions.php this code

what this code do is to search for the embed code of youtube and add to it

in order to change it with css


add_filter('embed_oembed_html', 'wrap_embed_with_div', 10, 3);

function wrap_embed_with_div($html, $url, $attr) {
        return "<div class=\"responsive-container\">".$html."</div>";
}

and this css code to your css file or theme settings css


.responsive-container {
        position: relative;
        padding-bottom: 50.25%;
        padding-top: 30px;
        height: 0;
        overflow: hidden;
        margin-bottom: 1em;
}
.responsive-container iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
}


hope i helped someone in this world 🙂

Advertisements

Disable the responsive image ‘srcset’ on WordPress 4.4

I got email from client about theme i did rtl that the gallery is nit changing main pic after u press on the thumbs and when i look at the code i found new element called srcset which was making this problem after searching google i found this temp solution for this all u need to d o is to add this code into functions.php in your theme


add_filter( 'max_srcset_image_width', create_function( '', 'return 1;' ) );