Wordpress Tricks

How to remove image from wordpress post content?

Wordpress send pdf with wp_mail function

Remove image from wordpress post content


Hello to all, welcome to therichpost.com. In this post, I will tell you, How to remove image from wordpress post content? 

Here is the working code and you can add this into your wordpress theme’s any template file:
$content = get_post_field('post_content', $post_id);
$content = preg_replace("/<img[^>]+\>/i", "", $content);


$content = get_the_content();
$content = preg_replace("/<img[^>]+\>/i", " ", $content);          
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;

 If you any query related to wordpress then comment or email me.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Positive SSL