Skip to content

Instantly share code, notes, and snippets.

@sthembi
Last active December 12, 2015 08:19
Show Gist options
  • Select an option

  • Save sthembi/4743324 to your computer and use it in GitHub Desktop.

Select an option

Save sthembi/4743324 to your computer and use it in GitHub Desktop.
Remove image width and height declaration in WordPress
//add to functions.php
//remove inline width and height added to images
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
// Removes attached image sizes as well
add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );
function remove_thumbnail_dimensions( $html ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment