Why html tags are being appended to my pictures?

I have a WordPress Network installation.
In main site, there is no problem (at least related to on I’m talking about it here) but meanwhile in the other site (my subdomain site) pictures appear to be gone!
Actually They are corrupt and when I opened one of them, I found some html codes are appended to them.
This problem has been occurred to me before. If I re-update the WordPress and then all sites, the problem seems to be solved but, after some time it will show up again.
Some month ago I had this problem and couldn’t find a solution. Time passed and it went by itself or maybe some WordPress updates made it gone. I checked plugins last time and deactivating them was no help.
This is the HTML code appended to pictures.

<div style="display:none"><b></b>..</div>

1 Answer
1

Sometimes, WordPress likes wrapping <img ... tags with extra HTML.

You could try something like as listed on http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/.

In your theme’s functions.php file, add the following lines of code near the top:

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');

Leave a Comment