Categories

Thursday, March 28, 2024
#919814419350 therichposts@gmail.com
Wordpress Tricks

How to remove image from wordpress post content?

How to add custom meta title and meta description in Wordpress?

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

//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.

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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