Skip to content
Create a gist now

Instantly share code, notes, and snippets.

img unautop
// img unautop, Courtesy of Interconnectit
// 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.