Created
November 23, 2010 13:44
-
-
Save jeremyboggs/711775 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
/** | |
* Removes inline width and height attributes for images. Thanks to | |
* @boonebgorges and @wayne_graham for help with this! | |
*/ | |
function clioweb_remove_inline_sizes($html) { | |
$pattern = '/(\sheight|\swidth)="(.*?)"/'; | |
$html = preg_replace($pattern, '', $html); | |
return $html; | |
} | |
add_filter( 'get_image_tag', 'clioweb_remove_inline_sizes', 10, 1 ); |
Terrific Wayne, thanks! I was actually wondering about that. Will update the code.
In case you didn't see the notice, I smashed the regex into a single check to avoid loop check https://gist.github.com/720074
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This only handles one case (height="100"), but height="100px" is not matched here:
There are a few ways to do handle this, here's one:
$patterns = array('/height="[a-zA-Z0-9]+" /', '/width="[a-zA-Z0-9]+" /');