Here’s the question ( and code ) from a member of the Genesis community:
I’m trying to remove the post info from posts in all categories except 2. I have used the following snippet but it is not working. Can anybody tell me what have I done wrong please?
add_filter( 'genesis_post_info_output', 'remove_single_post_info' );
function remove_single_post_info( $post_info ) {
if ( is_singular() && ! is_category( 'blog, breed-notes' ) ) {
remove_action( 'genesis_entry_header', 'my_post_info', 12 );
}
}
Answer :
There’s 4 problems with the above code:
1. The 1st line of code is wrong because we don’t want to filter the genesis_post_info_output. What we want to do is hook in a new function before the genesis_entry_header hook fires so we can remove the genesis_post_info function conditionally.
2. The 3rd line of code uses is_category which returns true on category pages. We need to use in_category which returns true on single posts in specific categories as we want to exclude removing the post info from all single posts in categories blog and breed-notes.
3. Again, on the 3rd line of code, we need to add a array() when using multiple comma separated values for the in_category conditional tag.
4. The 4th line of code needs to remove the default function from Genesis which adds the post info using the genesis_entry_header hook. The 2nd parameter used is my_post_info which isn’t correct and therefore needs changing to genesis_post_info.
Here’s the correct code:
The Correct Code
add_action( 'genesis_before_loop', 'remove_single_post_info' );
function remove_single_post_info( $post_info ) {
if ( is_singular( 'post' ) && ! in_category( array( 'blog', 'breed-notes' ) ) ) {
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
}
}
Using a code editor and FTP, add the above code to the end of your child themes functions.php file.
Was This Tutorial Helpful?