WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Hide post images but keep thumbnail image in Category archive (6 posts)

  1. wellhall12
    Member
    Posted 2 years ago #

    Hi basically within my home page i show my latest posts which have there own thumbnail, and within the posts there are images. however i did add the following code into "functions.php" which enabled me to hide the images but keep the thumbnail being shown:

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

    Basically when the post is shown in the category list the thumbnail and the images of the post are shown, which is not what i want. I want the thumbnail image to show and the post images to be hiden like at the home page.

    Please help someone

  2. patv
    Member
    Posted 2 years ago #

    You can use the following conditional tag and include this in your check:

    is_category()
    reference

  3. wellhall12
    Member
    Posted 2 years ago #

    okay so what would the following code look like? sorry im not very good with this.

    something like

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

    [Moderator Note: Please post code or markup snippets between backticks or use the code button.>]

  4. patv
    Member
    Posted 2 years ago #

    well, if your original code worked, then yes, that's the idea. Also include your s_home() || is_front_page() conditional check if you want to maintain the old behaviors. But yeah that's the idea, hopefully that'll give you the desired effect.

  5. wellhall12
    Member
    Posted 2 years ago #

    Thanks for your help

    The following code worked

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

    [Moderator Note: Please post code or markup snippets between backticks or use the code button.>]

  6. Alex.R
    Member
    Posted 2 years ago #

    Thank you so much "wellhall12" I've been looking for a solution to hide post images on category post previews. Your code worked perfectly.

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags