Skip to content

Instantly share code, notes, and snippets.

@acarabott
Created December 16, 2013 23:41
Show Gist options
  • Save acarabott/7997115 to your computer and use it in GitHub Desktop.
Save acarabott/7997115 to your computer and use it in GitHub Desktop.
Wordpress remove content image dimensions without regexp
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