- This topic has 21 replies, 3 voices, and was last updated 5 years, 8 months ago by
Tom.
-
AuthorPosts
-
July 17, 2020 at 1:46 am #1366430
Jon
I’m using the below code to display post categories below the title on my blog archive pages.
It works great, but how to I prevent the categories from also displaying on the single post pages?
add_filter( 'generate_show_categories', '__return_false' ); add_action( 'generate_after_entry_title', function() { $categories_list = get_the_category_list( ' | ' ); if ( $categories_list ) { printf( '<div class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</div>', esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ), $categories_list ); } } );July 17, 2020 at 8:05 am #1366880Leo
StaffCustomer SupportHi there,
There should be an easier way to do this now.
Any chance you can link us to the site in question?
You can edit the original topic and use the private URL field.
Let me know 🙂
July 17, 2020 at 8:08 am #1366886Jon
Hi Leo, thanks very much, I’ve added the URL.
I currently have the categories on the single post page hidden using CSS.
July 17, 2020 at 11:39 am #1367080Leo
StaffCustomer SupportWe can actually use this filter now:
https://docs.generatepress.com/article/generate_header_entry_meta_items/So remove your existing snippet and replace it with this one:
add_filter( 'generate_header_entry_meta_items', function( $items ) { if ( is_front_page() && is_home() ) { $items = array( 'categories', ); } return $items; } );July 18, 2020 at 1:54 am #1367464Jon
Hi Leo, thanks for that.
The categories are now displaying on the correct pages, but they’re back in their regular spot, how do I place them underneath the entry title again?
Cheers,
Jon
July 18, 2020 at 8:16 am #1367832Leo
StaffCustomer SupportHmm my snippet should make it show right below the post title – just tested as well.
Are you adding any other functions for the meta?
July 18, 2020 at 8:27 am #1367850Jon
Hey Leo,
Nope, nothing else, just the code snippet you suggested. The categories show below the excerpt.
July 18, 2020 at 8:34 am #1367854Leo
StaffCustomer SupportCan you clear and disable WP Rockets and any other caching plugins or server cache for now?
July 18, 2020 at 8:38 am #1367860Jon
Sure, cache is now cleared and deactivated.
July 18, 2020 at 1:59 pm #1368079Leo
StaffCustomer SupportI’m still seeing WP Rocket enabled.
Can you double check?
July 19, 2020 at 4:16 am #1368495Jon
I re-activated it again before going to bed last night (I’m based in the UK), as it makes quite a difference in the speed of the site.
It’s deactivated again now.
Thanks.
July 19, 2020 at 8:09 am #1368760Leo
StaffCustomer SupportYou are using Code Snippets?
Can you make sure the snippet is activated?
I’m having a tough time seeing why it’s not working.
Try removing this CSS as well:
https://www.screencast.com/t/7zXoj4Zam3July 19, 2020 at 8:24 am #1368778Jon
Yes I’m using Code Snippets, the snippet is activated.
I’ve removed the CSS.
July 19, 2020 at 4:28 pm #1369073Tom
Lead DeveloperLead DeveloperHi there,
Try this instead:
add_filter( 'generate_header_entry_meta_items', function( $items ) { if ( is_archive() || is_home() ) { $items[] = 'categories'; } return $items; } ); add_filter( 'generate_footer_entry_meta_items', function( $items ) { return array_diff( $items, [ 'categories' ] ); } );July 20, 2020 at 5:47 am #1369529Jon
Hi Tom, no joy I’m afraid, the categories aren’t showing at all now.
-
AuthorPosts
- You must be logged in to reply to this topic.