Created
January 28, 2012 22:55
-
-
Save rickbenetti/1696087 to your computer and use it in GitHub Desktop.
img unautop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$class+$align
breaks this, writing0">
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.