- This topic has 11 replies, 3 voices, and was last updated 1 year, 6 months ago by
Tom.
-
AuthorPosts
-
November 22, 2020 at 5:51 am #1540897
William
Hi there,
For the secondary menu on my site, on posts such as this, for mobile, it should and does show ‘Explore [category]’.For secondary categories, such as this, it also works correctly.
For primary category posts, such as this, it works correctly.
However, for the primary category page itself, such as this, it shows the secondary category. In this example, it states ‘Explore [secondary category under primary category]’ rather than ‘Explore [primary category]. It should say ‘Explore George Orwell’ rather than ‘Explore 1984’.
Can you help to provide a solution for this please?
Many thanks,
Will
November 22, 2020 at 10:53 am #1541368Leo
StaffCustomer SupportHi there,
What is the code you are using to change the menu label text?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 23, 2020 at 1:42 pm #1543069William
Hi there,
This was the below code – came from you guys I think from recall:
add_filter( 'option_generate_secondary_nav_settings', function( $settings ) { $category = get_the_category(); if ( $category ) { $settings['secondary_nav_mobile_label'] = 'Explore ' . $category[0]->cat_name; } return $settings; } );
November 24, 2020 at 11:35 am #1544971Tom
Lead DeveloperLead DeveloperHi there,
Your code will take the first category in the list and output it:
$category[0]->cat_name
The
[0]
will grab the first entry returned byget_the_category()
.I’m not sure how WordPress determines that order.
You could try this:
add_filter( 'option_generate_secondary_nav_settings', function( $settings ) { if ( is_category() ) { $category = single_term_title( '', false ); } else { $category = get_the_category(); if ( $category ) { $category = $category[0]->cat_name; } } if ( isset( $category ) ) { $settings['secondary_nav_mobile_label'] = 'Explore ' . $category; } return $settings; } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 24, 2020 at 2:07 pm #1545156William
Hi there,
I added the above as a snippet and it seemed to break the site – was that where I was to add the code?November 25, 2020 at 10:05 am #1546827Tom
Lead DeveloperLead DeveloperWhat about the site broke? Did you get a specific error?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 25, 2020 at 10:33 am #1546887William
November 26, 2020 at 9:50 am #1550259Tom
Lead DeveloperLead DeveloperStrange, that almost looks like broken HTML – and this resolves completely if you deactivate the snippet?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 26, 2020 at 9:59 am #1550269William
That’s correct – issue of the secondary nav menu showing 1984 instead of George Orwell still persists
November 26, 2020 at 1:08 pm #1550604Tom
Lead DeveloperLead DeveloperCan you try the updated code?: https://generatepress.com/forums/topic/secondary-menu-not-showing-correct-menu-title/#post-1544971
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 26, 2020 at 4:50 pm #1550884William
That seems to have worked ๐ thank you ever so much!
November 27, 2020 at 9:24 am #1552932Tom
Lead DeveloperLead DeveloperYou’re welcome ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.