Created
December 16, 2013 23:41
-
-
Save acarabott/7997115 to your computer and use it in GitHub Desktop.
Wordpress remove content image dimensions without regexp
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
function remove_img_dimensions($html) { | |
$dom = new DOMDocument; | |
$dom->loadHTML($html); | |
$imgs = $dom->getElementsByTagName('img'); | |
foreach ($imgs as $img) { | |
$img->removeAttribute('width'); | |
$img->removeAttribute('height'); | |
} | |
$html = $dom->saveHTML(); | |
return $html; | |
} | |
add_filter('the_content', 'remove_img_dimensions'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment