Archived topic
Secondary menu not showing correct Menu title
11 replies · Started by William on November 22, 2020
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
Hi there,
What is the code you are using to change the menu label text?
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;
} );
Hi 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 by get_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;
} );
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?
What about the site broke? Did you get a specific error?

Strange, that almost looks like broken HTML - and this resolves completely if you deactivate the snippet?
That's correct - issue of the secondary nav menu showing 1984 instead of George Orwell still persists
Can you try the updated code?: https://generatepress.com/forums/topic/secondary-menu-not-showing-correct-menu-title/#post-1544971
That seems to have worked :) thank you ever so much!
You're welcome :)