Post Pic

How to: Prevent post images from being displayed on 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!

Leave a Comment

* Name, Email, Comment are Required