WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Feb 14 2012

How to Hide the Featured Image of a Specific Category on the Blog Page in Genesis

So, in case you forgot, in Genesis Featured Images can be added to the blog page by selecting the checkbox "Include the Featured Image?" in Genesis > Theme Settings > Content Archives (admin url: http://domain.com/wp-admin/admin.php?page=genesis#genesis-theme-settings-posts).

Genesis Content Archives
Click for Larger Image

So what if you wanted to remove the featured images of a specific category (say category ID 126 [to get the category ID, use a plugin called Simply Show IDs--makes it quite easy!])?

Here is what I did:

  1. Copied page_blog.php from the genesis directory, which only contains genesis() function call.
  2. Then added the following function.

[php]
add_action( 'genesis_before_post' , 'wps_no_feature_image' );
add_action( 'genesis_after_post_content' , 'wps_no_feature_image' );
/*
* Remove Featured Image from Small Group Show category on blog page
* @author Travis Smith
*
*/
function wps_no_feature_image() {
global $post;

if ( has_category( 126 , $post ) && 'genesis_before_post' == current_filter() )
remove_action( 'genesis_post_content', 'genesis_do_post_image' );
elseif ( has_category( 126 , $post ) && 'genesis_after_post_content' == current_filter() )
add_action( 'genesis_before_post_content', 'genesis_do_post_image' );
}
[/php]

First and foremost, we cannot simply remove the action and keep going because then it will be unhooked for all categories on that page after. So what's happening here?

Now, the Genesis Featured Image appears on the genesis_post_content hook. So I need to call my function before that hook (or earlier in priority) to remove that action. So I call the function on genesis_before_post which occurs before genesis_post_content. Then after I pass genesis_post_content hook, I need to add the action back for the next post.

So, if I am illustrating this, it's as though I am walking down the hallway approaching a hook with a hat that I was going to put on my head. Before I get to the hook, my brother takes the hat, and after I pass the hook, my brother puts the hat back on the hook for the next person.

Written by Travis Smith · Categorized: Genesis

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Comments

  1. Ali Hussain says

    March 1, 2012 at 3:11 am

    Hi, tahnks for the article
    How can i use it in a reverse way, i.e. featured images only for a certain category

    Reply
  2. Jon Loomer says

    March 18, 2012 at 8:47 pm

    Hey, Travis. How would I remove the “Filed Under” and “Tagged With” items in the content archives?

    Reply
    • Travis Smith says

      March 19, 2012 at 1:15 pm

      Hi Jon,

      That’s called post meta data. So something like this should help: https://wpsmith.net/2011/genesis/remove-or-change-post-info-or-post-meta/

      Reply
  3. Bojan says

    March 30, 2012 at 6:57 pm

    Is it possible to change size for FEATURED IMAGE OF A SPECIFIC CATEGORY ???

    Reply
    • Travis Smith says

      April 2, 2012 at 8:11 am

      Hello Bojan,

      Yes, you would need to use the genesis_pre_get_image filter to accomplish this.

      Thanks,
      Travis

      Reply
  4. Dave Thackeray says

    October 11, 2012 at 3:56 am

    Travis this is incredible – so impressed with the knowledge you have on coding.

    I have a question. I want category archives to have featured images alongside each post extract in the list, but at the same time I’m trying to configure a portfolio page.

    If I set featured image in Theme Settings, the portfolio page displays TWO images – because it’s pulling the featured image as well as the image I have set for it specifically in functions.php.

    Is there a way to overcome this – but have featured images display automatically in category archives?
    Thank YOU!

    Reply
  5. Scott says

    February 23, 2013 at 2:45 am

    If I need the featured image on regular archive page (so it is enabled in Genesis settings) but want to disable the featured image on a Custom Post Type page, how would I go about that?

    Reply
  6. Patrick Brown says

    July 25, 2013 at 5:08 pm

    Hi Travis,

    Thanks for this tip! I had one bit of feedback, though. This code as it is now only works on the first post of a certain category. After that it doesn’t work. I think that is because when it comes to the next iteration, the action was added back to genesis_before_post_content and not genesis_post_content. So, the next time around, it can’t remove the action again.

    Basically, at the end of the function, change ” add_action( ‘genesis_before_post_content’, ‘genesis_do_post_image’ ); ” to ” add_action( ‘genesis_post_content’, ‘genesis_do_post_image’ ); ” and it works perfectly for me!

    Reply
  7. Sarah says

    July 9, 2015 at 3:43 pm

    How would you grab a custom field (image) for the featured image of a specific category? For example, I have a blog of paintings in multiple categories (landscape, people, greeting cards, etc.). I want the painting in the greeting cards category to have a different featured image than the same painting showing up in the people category.

    Reply
  8. Sarah says

    July 9, 2015 at 3:48 pm

    How would you hide featured image for xhtml?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in