Skip to content

Instantly share code, notes, and snippets.

@rickbenetti
Created January 28, 2012 22:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickbenetti/1696087 to your computer and use it in GitHub Desktop.
Save rickbenetti/1696087 to your computer and use it in GitHub Desktop.
img unautop
// img unautop, Courtesy of Interconnectit http://interconnectit.com/2175/how-to-remove-p-tags-from-images-in-wordpress/
// add img class and alignment to figure by @_RickBenetti
function img_unautop($pee) {
$class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
$pee = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<figure class="'. $class+$align .'">$1</figure>', $pee);
return $pee;
}
add_filter( 'the_content', 'img_unautop', 30 );
@jasonhibbs
Copy link

$class+$align breaks this, writing 0"> in front of images. I wish I knew why, but removing it fixes the problem. I haven’t found a way to get the img classes in the figures though, sadly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment