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.
<?php $content = get_the_content();</p> <p>$postOutput = preg_replace('/<img[^>]+./','', $content);</p> <p>echo $postOutput; ?>
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.
Hostgator Hosting in 1 Cent Coupon Code – “1CENTHECOUPON” (Without Quotes).