[resolved] Hide caption front page (6 posts)

  1. sandman1485
    Posted 6 years ago #

    I'm trying to hide image captions from my index.php/front page on http://www.indieshuffle.com/

    Please note that to see an example, look at "The Octopus Project" post on http://www.indieshuffle.com/?paged=2 (this may have been bumped to paged=3 or 4 by the time you read this).

    I'm using the following code in my functions.php to keep images off the front (and it works like a charm), but the captions still appear:

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

    How would I get this to work for captions?

  2. s_ha_dum
    Posted 6 years ago #

    Not sure I understand. I see images on your front page... ??? Exactly what have you removed and exactly what are you trying to remove?

  3. sandman1485
    Posted 6 years ago #

    You're seeing thumbnails on the front page, which do not show up in the actual post. Sorry for the confusion, but those are not the issue.

    As I said, I've only got one post set with this "caption problem", and that is the Octopus Project post on paged=2 right now. You should see "click image to view in itunes." That is the caption on the image that you see in the post when you go here: http://www.indieshuffle.com/?p=811

    I am trying to ensure that that caption no longer shows up on the front page. Hope that clarifies things.

  4. s_ha_dum
    Posted 6 years ago #

    That does make more sense.

    Here is the part that you need to filter:

    `<div id="attachment_816" class="wp-caption alignright" style="width: 310px;"><p class="wp-caption-text">click image to view in itunes</p></div>

    You should be able to use the same approach as before using a regex something like '/<div id="attachment.*<\/div>/. That one probably won't work. I never get them right on the first try, but you get the idea. I think you could also do this with CSS and save a lot of headache and CPU cycles-- set wp-caption {display:none} for your front page, or maybe narrow that down some and set it only within id="feature".

  5. sandman1485
    Posted 6 years ago #


    insert this in the header:

    <?php if ( is_home() )
    add_filter('img_caption_shortcode', create_function('$a, $b, $c',
    'return $c;'), 10, 3); ?>

  6. dizzyvapor
    Posted 6 years ago #

    Thanks for solving this! sandman1485, would you happen to know how I can modify this code so it doesn't show captions on archives and search results too?

Topic Closed

This topic has been closed to new replies.

About this Topic