WordPress.org

Ready to get started?Download WordPress

Forums

How to hide images from front page (8 posts)

  1. silentvoice84
    Member
    Posted 5 years ago #

    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

  2. chaoskaizer
    Member
    Posted 5 years ago #

    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);
    }
    ?>
  3. silentvoice84
    Member
    Posted 5 years ago #

    Hi

    The images are still displayed.

    did i miss something ?

  4. chaoskaizer
    Member
    Posted 5 years ago #

    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;
    }
    ?>
  5. silentvoice84
    Member
    Posted 5 years ago #

    yes that did the trick thanks :)

  6. jageland
    Member
    Posted 4 years ago #

    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!!

  7. Homeroma
    Member
    Posted 4 years ago #

    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.

  8. Tanha Karim
    Member
    Posted 4 years ago #

    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 ?

Topic Closed

This topic has been closed to new replies.

About this Topic