WordPress.org

Support

Support » Themes and Templates » How to hide images from front page

How to hide images from front page

  • Greetings,

    In each post at front page there are couple of images and screen shots, i was looking for a solution to hide images in post only in front page.

    the <?php the_excerpt(','); ?> is good but i don’t know how to customize it to make it only hide the image tag

    thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • add the following code inside your theme’s functions.php

    <?php
    if (is_home() || is_front_page()){
        add_filter('the_content','wpi_image_content_filter',11);
    }
    
    function wpi_image_content_filter($content){
        return preg_replace("/<img[^>]+\>/i", "", $content);
    }
    ?>

    Hi

    The images are still displayed.

    did i miss something ?

    whoops changed it too

    <?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;
    }
    ?>

    yes that did the trick thanks 🙂

    I’ve been looking for exactly this thing and it works perfectly!! Love it!!

    Only one thing…
    When having it installed it does something to the rest of the function.php file. I can’t log in, comment, update the site etc. The script works brilliantly but not the rest of the site.

    Any idea what the problem might be?

    BTW, this is what comes up:

    Cannot modify header information – headers already sent by (output started at /home/content/h/a/m/hampus/html/test/wp-content/themes/test/functions.php:15) in /home/content/h/a/m/hampus/html/test/wp-includes/classes.php on line 1586

    Thanks!!

    Homeroma

    @homeroma

    Hi everyone,

    could someone please help me as I have been tearing my hair out for the last few days trying to figure this out.

    What I would like to do on my website is have 3 images on the index page for each post and when clicking on the post I would like 1 to disappear.

    I thought I would be able to try and integrate div classes with the code that chaoskaizer posted above but is not working at all. So really the one that would disappear would have a different div class to the other two.

    Any help would be much appreciated.

    i also get errors …. help me to sort out

    Warning: Cannot modify header information – headers already sent by (output started at /home/careersi/public_html/wp-content/themes/tigopedia-reloaded/functions.php:25) in /home/careersi/public_html/wp-includes/pluggable.php on line 868

    how to solve it ?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to hide images from front page’ is closed to new replies.
Skip to toolbar