Skip to content

@rickbenetti /wordpress-img-unautop
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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

$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
Something went wrong with that request. Please try again.