Uncornered Market (coming soon…)
002houston Magazine
Pinkalicious
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).
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:
- Copied page_blog.php from the genesis directory, which only contains genesis() function call.
- 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.
- « Previous Page
- 1
- …
- 24
- 25
- 26
- 27
- 28
- …
- 61
- Next Page »