Skip to content

Instantly share code, notes, and snippets.

@scottlyttle
Created February 5, 2013 00:39
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 scottlyttle/4711107 to your computer and use it in GitHub Desktop.
Save scottlyttle/4711107 to your computer and use it in GitHub Desktop.
Remove the width and height attributes from an inserted image in WordPress
add_filter( 'get_image_tag', 'remove_width_and_height_attribute', 10 );
add_filter( 'post_thumbnail_html', 'remove_width_and_height_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_width_and_height_attribute', 10 );
function remove_width_and_height_attribute( $html ) {
return preg_replace( '/(height|width)="\d*"\s/', "", $html );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment