Archived topic
Hide post date on most, but not all, posts
11 replies · Started by johlor on May 21, 2017
I'm trying to use the filter to hide the post date on all but two of my categories. I tried working with the code in the docs, but I have no idea what any of it means. I'd appreciate any help to get it working properly. Thanks.
Here's where I got the idea.
https://docs.generatepress.com/article/generate_post_date_output/
Here's the code I came up with to see if I could make it happen on one category. I created and activated it with Code Snippets (A completely awesome plugin - great referral Tom), but it doesn't work.
add_filter( 'generate_post_date_output','johlor_post_type_remove_date' );
function johlor_post_type_remove_date( $output ) {
// If we're not on our "blog" post type, remove the date.
if ( not_post_type_archive( 'blog' ) || 'blog' == get_post_type() ) {
return '';
}
// Otherwise, display it.
return $output;
}
The two categories I need the date to appear on are "blog" and 'bignews'.
I'm sure I missed something.
Hi there,
The blog is actually a category? If so can you give this a shot?
add_filter( 'generate_post_date_output','johlor_post_type_remove_date' );
function johlor_post_type_remove_date( $output ) {
if ( is_category( array( 'blog', 'bignews' ) ) ) {
return $output;
}
return '';
}
Didn't work. I received this error on the Code Snippets page.
The snippet has been deactivated due to an error on line 3:
syntax error, unexpected '{'
Sorry there was a syntax error. Can you try it again?
Did you add a change to the code? I don't see it.
Yup it was missing a closing bracket )
Getting closer. It hid the date on all posts.
The above code will only display the date on the "blog" and "bignews" categories. Can you link us to one of those categories possibly?
Sorry for the delayed response. The site is still under construction, so I've given you admin access. The "sample" posts have a description of what I'm trying to do.
Did you email me the admin access?: https://generatepress.com/contact/
It didn't send when I created the user? I used support@generatepress.com.
Which form should I use on your Contact page to send the credentials?
I'm not seeing any categories named bignews or blog on your site?