Skip to content

Instantly share code, notes, and snippets.

@neverything
Created July 14, 2014 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neverything/3d4e9e728d564ecbfb11 to your computer and use it in GitHub Desktop.
Save neverything/3d4e9e728d564ecbfb11 to your computer and use it in GitHub Desktop.
Remove the width and height attribute from all WordPress images
<?php
/**
* Remove width and height from all the WordPress images.
*
* @param $html
*
* @return mixed
*/
function remove_thumbnail_dimensions( $html ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment