In January, I posted how much I really hate WordPress’ automatic post formatting, and we will continue it today on this post. That tutorial removes automatic paragraph tags in WordPress, but what if we just want to remove them from images?
Here’s how you can remove paragraph tags from around images in WordPress to make them look exactly what you want. We can fix it with this snippet. Just drop the following snippet to your current theme’s functions.php file:
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
Thanks to CSS Tricks for the snippet!