Support » Plugins » Avoid pictures on the frontpage/category pages

  • Hi,

    I’m using the “more” tag to avoid showing all of my posts on the frontpage/category pages.

    Problem is that some of my posts have a picture in the beginning and that the pictures are shown on the frontpage/category pages.
    (see here:

    Is there a way to modify the code, so post pictures aren’t shown on the frontpage/category pages?

    Thanks, Mads

Viewing 6 replies - 1 through 6 (of 6 total)
  • the easiest way that i can think of would be to use css

    set a unique class for the divs where you don’t want the images to appera (e.g. noimg);

    then in css:

    .noimg img { display:none; }

    Yes, but they should only be gone on the front page/category pages, not on the individual post pages.

    If I use the CSS solution, I need some way of telling WP which image class to use where.

    Actually, no need to set a class for the images specifically. You can slip this into your theme’s header.php (or where ever the <head> sits in your templates):

    <?php if( !is_single() && !is_page() ) : ?>
    <style type="text/css">
    .post img {
    	display: none;
    <?php endif; ?>

    Make sure, if necessary, to modify the .post class to one you use for your posts, typically a class for a div element each post resides in in the layout.

    For a purely PHP method that removes rather than hides the images through css, replace:

    <?php the_content(); ?>

    in any templates where you do not want images displayed with:

    <?php echo preg_replace( '/<img[^>]*>/i', '', apply_filters('the_content', get_the_content()) ); ?>

    In the case where say single.php and page.php templates are missing in action for a theme:

    if( is_single() || is_page() ) :
    else :
    	echo preg_replace( '/<img[^>]*>/i', '', apply_filters('the_content', get_the_content()) );

    The category pages usually use the_excerpt() rather than the_content(), so shouldn’t show any images anyway. You could also try this on your front page.

    Outstanding answers! Thank you everybody, it works now.

    hi, i have a problem with assigning a class to an image in wordpress. i know that the code should look like this to have an image displayed the way i wan to:

    <img src=”” height=”136″ width=”180″ class=”left”/>

    i can easily add the class when i’m logged in as an administrator, but when i try to do it when i’m logged in as an author, this part of class=”left” is being deleted automatically. please advise.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Avoid pictures on the frontpage/category pages’ is closed to new replies.