Skip to content

Instantly share code, notes, and snippets.

@stinoga
Created August 1, 2012 02:32
Show Gist options
  • Save stinoga/3223062 to your computer and use it in GitHub Desktop.
Save stinoga/3223062 to your computer and use it in GitHub Desktop.
Responsive images in Wordpress posts
// Remove image width/height, so everything can work responsively in posts
function strip_size($html, $id) {
$html = preg_replace('/\<(.*?)(width="(.*?)")(.*?)(height="(.*?)")(.*?)\>/i', '<$1$4$7>',$html);
return $html;
}
add_filter('get_image_tag', 'strip_size', 10, 2);
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( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
add_filter( 'wp_get_attachment_image_attributes', 'remove_thumbnail_dimensions', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment