i have put this function in the functions.php theme file:
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');
After that the whole pages content are gone, i have deleted that function from functions.php but the content still not showing, any ideas why?
Try with this: <p>\s*(<a[^>]*>)?(<img[^>]+>)(<\/a>)?\s*<\/p>
It will also work with images within <a>
tags.
Explained:
<p> # p tag
\s* # 0 or more spaces
(<a[^>]*>)? # optional <a> tag: (first capturing group)
# it matches <a and then any non '>' character
# repeated 0 or more times and then a '>'
# (second capturing group)
(<img[^>]+>) # image tag
(<\/a>)? # optional closing </a> (third capturing group)
\s*
<\/p>