- This topic has 11 replies, 3 voices, and was last updated 3 years, 4 months ago by Tom.
-
AuthorPosts
-
November 22, 2020 at 5:51 am #1540897William
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 #1541368LeoStaffCustomer SupportHi there,
What is the code you are using to change the menu label text?
November 23, 2020 at 1:42 pm #1543069WilliamHi 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 #1544971TomLead 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; } );
November 24, 2020 at 2:07 pm #1545156WilliamHi 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 #1546827TomLead DeveloperLead DeveloperWhat about the site broke? Did you get a specific error?
November 25, 2020 at 10:33 am #1546887WilliamNovember 26, 2020 at 9:50 am #1550259TomLead DeveloperLead DeveloperStrange, that almost looks like broken HTML – and this resolves completely if you deactivate the snippet?
November 26, 2020 at 9:59 am #1550269WilliamThat’s correct – issue of the secondary nav menu showing 1984 instead of George Orwell still persists
November 26, 2020 at 1:08 pm #1550604TomLead DeveloperLead DeveloperCan you try the updated code?: https://generatepress.com/forums/topic/secondary-menu-not-showing-correct-menu-title/#post-1544971
November 26, 2020 at 4:50 pm #1550884WilliamThat seems to have worked ๐ thank you ever so much!
November 27, 2020 at 9:24 am #1552932TomLead DeveloperLead DeveloperYou’re welcome ๐
-
AuthorPosts
- You must be logged in to reply to this topic.