Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

img unautop

View wordpress-img-unautop
1 2 3 4 5 6 7 8
// 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 );

$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.