Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 134420

Charliebee1990 on "Remove 'p' tags v from images function query"

$
0
0

Hi there,

I found a solution to remove to the p tags from images when creating a post which works however only for one image.

For the image that it works for, i looked at firebug and this is what is shown:

<div class="entry-content">
<a href="http://localhost:8888/wordpress/wp-content/uploads/2013/02/img-1.png">
<img class="alignnone size-full wp-image-50" width="520" height="320" src="http://localhost:8888/wordpress/wp-content/uploads/2013/02/img-1.png" alt="img-1">
</a>

and so on....great!

But when i upload another image to another post this happens:

<p>
<img class="alignnone size-full wp-image-50" width="520" height="320" src="http://localhost:8888/wordpress/wp-content/uploads/2013/02/img-1.png" alt="img-1">
<br>
Lorem ipsum dolo....
</p>

This is the function i'm using in my functions file:

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

So is there a way off adding another "return line" with a function of removing the p tags when its just <p><img> as it only seems to work when its <p><a'><img>..? I hope this makes sense! If it helps this is my css for my images:

width:100%;
height:auto;
min-width:320px;
}

I just want the image to be the full width of my post and the content to use the paragraph tags, as i say it worked for my first image but not for any others!

Thanks


Viewing all articles
Browse latest Browse all 134420

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>