- This topic has 5 replies, 3 voices, and was last updated 3 years, 9 months ago by Tom.
-
AuthorPosts
-
June 12, 2020 at 11:42 pm #1325900Joezer
Hello awesome people of Generatepress!
My setup is:
Layout>Blog>Archives>Display post categories. I only want the category of the post to show up in search results. But in the category archive pages like site.com/category/cars, I want to hide the category links under the post titles, since it is pointing to the same page (site.com/category/cars) that is listed. Is there something that I could add in my functions to set it so that the post’s category links are not rendering in the category archives?I tried to display:none but it is still showing in the source code. Problem with this is that if a category archive is showing 20 post titles under that category, then the category meta link is showing 20 times for that. And since I very rarely use multiple categories for this site’s posts, I have 20 category meta link that is basically just pointing to the same page.
June 13, 2020 at 4:13 am #1326103DavidStaffCustomer SupportHi there,
you can use the Blog Options filter:
https://docs.generatepress.com/article/option_generate_blog_settings/
Something like this which should disable categories unless its the search page:
add_filter( 'option_generate_blog_settings', 'db_custom_search_show_category' ); function db_custom_search_show_category( $options ) { if ( !is_search() ) { $options['categories'] = false; } return $options; }
June 13, 2020 at 6:32 am #1326209JoezerHello David,
It works! But the custom post types appearing in the search result doesn’t show the categories. It only shows the title while the regular posts works without problem. How do I make this so that it will also be included in the CPTs? I searched around and found this:
add_filter( ‘generate_footer_meta_posts_types’, function( $types ) {
$types[] = ‘pictures’;return $types;
} );But I think this is not it..
The CPTs are using the categories from WordPress core.
Thanks, David.
June 13, 2020 at 4:07 pm #1326825TomLead DeveloperLead DeveloperIf you’re using the core categories, then that code should work. You just need to change
pictures
to the name of your CPT.June 13, 2020 at 9:07 pm #1326935JoezerHello Tom,
I changed it, but it is still not showing. Kindly see this SS.. https://prnt.sc/szc9dk
This is the code that I have in my functions.php
add_filter( 'option_generate_blog_settings', 'db_custom_search_show_category' ); function db_custom_search_show_category( $options ) { if ( !is_search() ) { $options['categories'] = false; } return $options; } add_filter( 'generate_footer_meta_posts_types', function( $types ) { $types[] = 'vip'; return $types; } );
June 14, 2020 at 10:00 am #1327593TomLead DeveloperLead DeveloperCan you link me to a VIP post/archive?
-
AuthorPosts
- You must be logged in to reply to this topic.