Created
May 1, 2018 17:17
-
-
Save rugor/95c6e08eea54adb962460b50a7db36e9 to your computer and use it in GitHub Desktop.
PHP: WordPress remove width and height from image tags for responsive images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Removes width and height attributes from image tags | |
* | |
* @param string $html | |
* | |
* @return string | |
*/ | |
function remove_image_size_attributes( $html ) { | |
return preg_replace( '/(width|height)="\d*"/', '', $html ); | |
} | |
// Remove image size attributes from post thumbnails | |
add_filter( 'post_thumbnail_html', 'remove_image_size_attributes' ); | |
// Remove image size attributes from images added to a WordPress post | |
add_filter( 'image_send_to_editor', 'remove_image_size_attributes' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment