Hide Featured Image on Index Pages

Hello,

I want to hide the featured images for my blog posts on the main blog index and any archive indexes (for example, category, tag or monthly archives).

I found the solution to hide featured images from single blog posts (see below). Can you help me tweak it so that it can hide the pages mentioned above, too, please?

P.S. I am making these changes in my child theme.

<?php // ============================================================================= // VIEWS/INTEGRITY/CONTENT.PHP // ----------------------------------------------------------------------------- // Standard post output for Integrity. // ============================================================================= ?> > <?php if ( ! is_single() ) : ?>
<?php x_featured_image(); ?>
<?php endif; ?>
<?php x_get_view( 'integrity', '_content', 'post-header' ); ?> <?php x_get_view( 'global', '_content' ); ?>
<?php x_get_view( 'integrity', '_content', 'post-footer' ); ?>

Hello There,

Thanks for writing in! To resolve your issue, please remove this block:

 <?php if ( ! is_single() ) : ?>

  <?php x_featured_image(); ?> 

<?php endif; ?>

And replace it with this code:

 <?php if ( ! is_single() || is_home() || is_archive() ) : ?>

  <?php x_featured_image(); ?> 

<?php endif; ?>

You can find more about the different WordPress conditional tags from here: https://codex.wordpress.org/Conditional_Tags

Hope this helps.

Hi @RueNel,

Thank you for this! I gave it a try and nothing changed. I also noticed that some of the code that I copied/pasted above, with my original question, doesn’t appear in my post! I’m uploading an image of the file with this response. (This is the version that I have live on my site right now.)

Can you please see if I properly pasted the code?
Shannon

Also, how are you creating the sections of your response with code? I used to know how to do that in the old forum, but I don’t see the option in the current forum interface. Thank you!

Hello There,

Sorry I forgot to negate the condition. Please use this:

 <?php if ( ! is_single() || ! is_home() || ! is_archive() ) : ?>

  <?php x_featured_image(); ?> 

<?php endif; ?>

The condition would mean if not single or not home (blog index) or not an archive page.

Please let us know if this works out for you.

Hi @RueNel,

I tried this version and it breaks the single post functionality, and still doesn’t work on the archive pages. (In other words, now all pages show the featured image.)

I:confused:

Hey There,

Could you please clarify where you only want to display the featured image?

We can then edit the code and have something like this:

<?php if ( condition ) : ?>

  <?php x_featured_image(); ?> 

<?php endif; ?>

wherein the condition is the only page you would like to display the featured image. If you want to totally remove the featured image anywhere, you can simply delete the whole if block.

Heya,

I only want to show the featured image in places where it’s a thumbnail. For example, on my homepage I show recent posts with thumbnails (see “Latest from the blog” section). I also want the featured image to show if I’m sharing the image on social.

Thank you,
Shannon

Hi Shannon,

Well in that case, simply remove the whole if block. The featured image will no longer be displayed anywhere else. The recent posts element will still display the image since it is using a different method of displaying the featured image. The image when you shared on the social network will still display the featured image since the Open Graph or your SEO plugin is the one in charge with that.

So the final code would be:

<?php

// =============================================================================
// VIEWS/INTEGRITY/CONTENT.PHP
// -----------------------------------------------------------------------------
// Standard post output for Integrity.
// =============================================================================

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>



  <div class="entry-wrap">
    <?php x_get_view( 'integrity', '_content', 'post-header' ); ?>
    <?php x_get_view( 'global', '_content' ); ?>
  </div>
  <?php x_get_view( 'integrity', '_content', 'post-footer' ); ?>
</article>

Hope this make sense.

Hey @RueNel,

Oh, that sounds easier. :stuck_out_tongue: Question—if I change my mind to show masonry layout on the archive pages, will the featured images be able to show there? (I’m OK with thumbnail sizes displaying, but I don’t ever want the full-sized images to appear.)

Thank you so much for all of your help.

Shannon

Hey Shannon,

If you use masonry layout, then you will have to display back the featured image. You might need to add a condition that would be same as the masonry layout. You can make use of this one:

<?php

// =============================================================================
// VIEWS/INTEGRITY/CONTENT.PHP
// -----------------------------------------------------------------------------
// Standard post output for Integrity.
// =============================================================================

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<?php
if ( is_home() ) :
  $style     = x_get_option( 'x_blog_style' );
  $cols      = x_get_option( 'x_blog_masonry_columns' );
  $condition = is_home() && $style == 'masonry';
elseif ( is_archive() ) :
  $style     = x_get_option( 'x_archive_style' );
  $cols      = x_get_option( 'x_archive_masonry_columns' );
  $condition = is_archive() && $style == 'masonry';
elseif ( is_search() ) :
  $condition = false;
endif;
?>

  <?php if ( $condition && $style == 'masonry' ) : ?>
  	<?php x_featured_image(); ?> 
  <?php endif; ?>


  <div class="entry-wrap">
    <?php x_get_view( 'integrity', '_content', 'post-header' ); ?>
    <?php x_get_view( 'global', '_content' ); ?>
  </div>
  <?php x_get_view( 'integrity', '_content', 'post-footer' ); ?>
</article>

Hope this helps.

This is great! Thank you for the help, I really appreciate your time!! :smiley:

You’re most welcome!
We’re just glad we were able to help you out.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.