Wordpress - Filter to remove image dimension attributes?
Thanks all!
The image_send_to_editor filter was the one I was looking for... thanks @t31os for pointing it out.
Here's my functions now.
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
function remove_thumbnail_dimensions( $html ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
This removes inline dimension attributes from images retrieved with the_post_thumbnail()
, and prevents those attributes from being added to new images added to the editor. Doesn't remove them from images retrieved through wp_get_attachment_image
or other related functions (no hooks in there), but those cases can be processed in the templates files when necessary.
Modified this script a bit. Thanks for the help!
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
// Genesis framework only
add_filter( 'genesis_get_image', '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;
}