How To Remove Images From WordPress Post Content

Hi Friends, In this article I am goind to explain how can we remove images from wordpress post content. Of course we can use the_excerpt() function but it will give you excerpt not post content, My need is to get post content without images, So to do that there is three line of code by which we can achieve easily.

&lt;?php $content = get_the_content();</p>
<p>$postOutput = preg_replace('/&lt;img[^&gt;]+./','', $content);</p>
<p>echo $postOutput; ?&gt;

So above is code by which we can remove images from post content and then get content without images. Here we have to use function get_the_content() because we have to get content in variable to remove images from that content. After that in second line of code we used preg_replace to remove <img> by blank value by using regular expression and in last line we have echo post content. So by this way we can remove images from posts.

I hope this post helpful for someone. If you have any question then you can ask me anytime or post it in comment.

Also I am WordPress Developer, Freelance PHP Developer having more than 3 years of experience, So if you want to do any projects then you can contact me.

Hostgator Hosting in 1 Cent Coupon Code – “1CENTHECOUPON” (Without Quotes).