
When using images in your posts, you not always want them to be shown on your blog homepage. In theses cases, here is a little piece of code that prevent any images from the post to be displayed on the homepage.

When using images in your posts, you not always want them to be shown on your blog homepage. In theses cases, here is a little piece of code that prevent any images from the post to be displayed on the homepage.
Simply paste this code in your functions.php file:
<?php
add_filter('the_content','wpi_image_content_filter',11);
function wpi_image_content_filter($content){
if (is_home() || is_front_page()){
$content = preg_replace("/<img[^>]+\>/i", "", $content);
}
return $content;
}
?>
Credits goes to Avice De’véreux for this awesome recipe!
13 Responses
If you don’t use images on home page it looks to typographic.
I prefer all my post with images (on Home page and single post) it looks nice and cool
I think removing images from the home page is a perfect solution for small posts, blogs with dozens of new posts per day, and of course, blogspam. But I needed it for a quasi-twitter blog. It worked well.
Nice tip.
I think some themes are designed to show images via custom field. I wish it was this easy to modify them too
Keep up the great work you are doing..
Perfect, just what I needed as the images really mess up the view on home page with excerpts.
I use a theme that not show image in the homepage. Now i know what the cause of it..
Can you use a similar function to be able to apply timthumb to images in the content too?
I actually made this custom filter for WP archive page (archive,date,tags,cats). The function is from http://code.google.com/p/wp-istalker/source/browse/branches/WordPress/2.7/1.6.2/lib/modules/filters.php#148
Thanks for spreading it out. Someone might find it useful
so many useful tricks ,think you very much.
OMG, I`ve looked everywhere for this code. Thank you !
Would I add the enclosing <?php brackets. Or would I remove these and place anywhere on the page. Because my images are not removed. But i'd like to remove the images and use the thumbnails instead.
Trackbacks: