clubmate.fi

A good[ish] website

Web development blog, loads of UI and JavaScript topics

How to remove image dimension attributes in WordPress

Filed under: WordPress/PHP— Tagged with: regex, responsive, snippets

Just a quick snippet. May come handy on responsive layouts.

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;
}

Source. More on the subject.

Comments would go here, but the commenting system isn’t ready yet, sorry.

  • © 2022 Antti Hiljá
  • About
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • I love u!