[Resolved] Secondary menu not showing correct Menu title

Home Forums Support [Resolved] Secondary menu not showing correct Menu title

Home Forums Support Secondary menu not showing correct Menu title

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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

    #1541368
    Leo
    Staff
    Customer Support

    Hi there,

    What is the code you are using to change the menu label text?

    #1543069
    William

    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;
    } );
    #1544971
    Tom
    Lead Developer
    Lead Developer

    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;
    } );
    #1545156
    William

    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?

    #1546827
    Tom
    Lead Developer
    Lead Developer

    What about the site broke? Did you get a specific error?

    #1546887
    William

    #1550259
    Tom
    Lead Developer
    Lead Developer

    Strange, that almost looks like broken HTML – and this resolves completely if you deactivate the snippet?

    #1550269
    William

    That’s correct – issue of the secondary nav menu showing 1984 instead of George Orwell still persists

    #1550604
    Tom
    Lead Developer
    Lead Developer
    #1550884
    William

    That seems to have worked ๐Ÿ™‚ thank you ever so much!

    #1552932
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.