Archived topic
Remove Post Author and Date based on category type
10 replies · Started by Joseph on May 10, 2019
I have certain categories that I do not want to show the author and date. I looked at the PHP documentation and found this for the date removal. How or does this also apply to the removal of the author?
add_filter( 'generate_post_author_output', function( $output ) {
// If we're on our "my-post-type" post type, remove the author.
if ( is_post_type_archive( 'my-post-type' ) || 'my-post-type' == get_post_type() ) {
return '';
}
// Otherwise, display it.
return $output;
} );
Thank you in advance.
Hi there,
maybe this article will be helpful:
https://docs.generatepress.com/article/option_generate_blog_settings/
I crashed the site adding the script to the themes.php. Got it back up. Can you assist with the proper code? The category I am looking to eliminate the author and date is American Heritage Center.
Thanks David, any help is appreciated.
Hi there,
Try this:
add_action( 'wp', function() {
if ( is_category( 'your-category-slug' ) ) {
add_filter( 'generate_post_date', '__return_false' );
add_filter( 'generate_post_author', '__return_false' );
}
} );
Just replace your-category-slug with your category.
Hi Tom, added the script and got the message at the very bottom of the attached image I have enclosed. Pretty straight forward but something is not working. I probably missed something.

I believe that means WordPress isn't communicating with the files well enough to update them.
You could try using a plugin like Code Snippets instead if you can't access the files via FTP.
Hi Tom. How about hiding the author byline in a certain category across the site? I have a guest category and I am hiding the byline in single posts using CSS like .category-category name .byline{display: none;}and the above function in code snippets didn't work.
Update: Tried this code and it worked. Hope it is a correct code?
add_action( 'wp', function() {
if ( has_category( array( 10 ) ) ) {
add_filter( 'generate_post_author', '__return_false' );
}
} );
That's perfect :)
Thanks...
Epic, thank you much!! That worked perfectly!!
You are welcome. I justly slightly modified a code shared by Tom in another post.