Automatically removing 'p' tags from the HTML
I have the following code, which supposedly removes all p tags that are
wrapped around images. I am literally copying and pasting this into my
functions.php. However, it's not working:
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .*
\/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
Do I need to change the function parameter with something more relevant to
my theme? I'm new to WordPress so apologies for what might seem like a
silly question.
No comments:
Post a Comment