As you may have noticed  my new site is fairly heavily responsive. A lot of extra work has gone into helping make the user experience for 50% of my visitors that use mobile devices. Now I love WordPress however it’s about time it started to move to accept modern methods like responsive design. That aside we can make a work around.

Using jQuery we can simply strip the attributes from images before being rendered. Now this will affect ALL images on your page.

jQuery(document).ready(function($) {
	$('img').removeAttr('width height');
});

Now obviously you need to get this into your theme somewhere. I personally have added it to my Global JS file which is already loaded. If you don’t have that you can simply create a file, call it whatever you like and enqueue the javascript in your themes functions.php.

function responsive_images() {
    wp_register_script( 'responsive-img', get_template_directory() . '/myfile.js', array( 'jquery' ), null, true );
    wp_enqueue_script( 'responsive-img' );
}

add_action( 'wp_enqueue_scripts', 'responsive_images' );

It’s not the best way of doing it, however it does work.

 Tagged with: , , , ,

Leave a Reply

Mojowill Avatar

Who the Hell am I?

I'm Will, a full time web developer, geek and musician. I develop using PHP and MySQL and spend most of my time working with WordPress or CakePHP. When I'm not buried in code I'm gaming, cooking or writing and recording music in my studio. I like sci-fi, pancakes and coffee and am totally prepared for the zombie apocalypse...

Stalk me on these other sites...

Why not be super creepy and check me out on all these other sites, I think they call it social media?