Site logo

Archived topic

Removing Width + Height Attributes from Featured Images

3 replies · Started by Janine on March 18, 2018

Viewing posts 1–4 of 4

I found this gist on Github:

/*--------------------------------------------------------------------------------------*/
/* Remove width/height attributes from featured image */
/*--------------------------------------------------------------------------------------*/
function remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10, 3 );

After I implement it, how would I know if it worked?

Thank you!

You can right click the image and click "Inspect". It will show you the HTML for the image.

Thanks, Tom.

No problem!

This archived topic is closed to new replies.