Skip to content

Instantly share code, notes, and snippets.

@stuntbox
Last active March 23, 2023 03:32

Revisions

  1. stuntbox revised this gist Jan 25, 2013. No changes.
  2. stuntbox revised this gist Jan 23, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    /**
    * Filter out hard-coded width, height attributes on all images images in WordPress.
    * Filter out hard-coded width, height attributes on all images in WordPress.
    * https://gist.github.com/4557917
    *
    * This version applies the function as a filter to the_content rather than send_to_editor.
  3. stuntbox revised this gist Jan 17, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    /**
    * Filter out hard-coded width, height attributes on all images images in WordPress.
    * https://gist.github.com/4557917
    *
    * This version applies the function as a filter to the_content rather than send_to_editor.
    * Changes made by filtering send_to_editor will be lost if you update the image or associated post
  4. stuntbox created this gist Jan 17, 2013.
    21 changes: 21 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    /**
    * Filter out hard-coded width, height attributes on all images images in WordPress.
    *
    * This version applies the function as a filter to the_content rather than send_to_editor.
    * Changes made by filtering send_to_editor will be lost if you update the image or associated post
    * and you will slowly lose your grip on sanity if you don't know to keep an eye out for it.
    * the_content applies to the content of a post after it is retrieved from the database and is "theme-safe".
    * (i.e., Your changes will not be stored permanently or impact the HTML output in other themes.)
    *
    * Also, the regex has been updated to catch both double and single quotes, since the output of
    * get_avatar is inconsistent with other WP image functions and uses single quotes for attributes.
    * [insert hate-stare here]
    *
    */
    function mytheme_remove_img_dimensions($html) {
    $html = preg_replace('/(width|height)=["\']\d*["\']\s?/', "", $html);
    return $html;
    }
    add_filter('post_thumbnail_html', 'mytheme_remove_img_dimensions', 10);
    add_filter('the_content', 'mytheme_remove_img_dimensions', 10);
    add_filter('get_avatar','mytheme_remove_img_dimensions', 10);