Wordpress Tricks

How to remove image from wordpress post content?

Remove image from wordpress post content

wordpress
175Views

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

//or

$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

Positive SSL