Responsive YouTube embedding for WordPress themes

The default code for embedding YouTube videos is an iframe with a set width and height. Iframes are not responsive and of course we want all content on our websites to be responsive. I found a neat solution to this at avexdesigns . However, this solution requires that you wrap the iframe in a container div. The whole point of using WordPress is to make life easy for our clients. We don’t want them to have to mess around with css and html. An easy fix for this is to dynamically wrap all iframe objects using jQuery.

Add the css from avexdesigns to your theme stylesheet. Then add simply add this little javascript to your theme

'); });

Assuming your theme is loading jQuery properly, any iframe code your customer adds to their site via WordPress admin will now be responsive automagically.