how to remove images from content of post in wordpress

WordPress is the best open source and very easy to install and set up on the site, when we working with the wordpress then its provide post content and page content and we can insert the images in the content using the editor. today i am working on project of my client and its in wordpress, if you aware of wordpress then you know that on the home page its show some post with the post title and post content. now issue is if there is a image in starting of post content then it will also show the image on the home page and because of that its looks messy page. now my client want to remove the images from the post content and display on the home page but in the single post page he need image as well. so i work on this and i get solution as well, below is the simple code which you can use to hide the images on the home page and you can use it to hide the inner page images as well if you want.

 
<?php
 
$original_content = get_the_content();
$new_content = preg_replace('/<img[^>]+./','', $original_content);
echo $new_content;
 
?>

Hope, it will be useful to you guys as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>