• Resolved FeliceAntonio

    (@antonio_09)


    Hi to everyone.
    With this code, I go to hide the Italian menu for the English category on the desktop.

    add_filter( 'generate_navigation_location','tu_move_navigation' );
    function tu_move_navigation( $location )
    {
    	if ( is_category( 11 ) && !wp_is_mobile() || in_category( 11 ) && !wp_is_mobile() ) {
    		return '';
            }
    	
    	return $location;
    }

    If I add code (that is English menu) inside return '' returns HTML entities, although the browser does not show anything, just on the code source page.
    Any ideas to work out?
    Thanks.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter FeliceAntonio

    (@antonio_09)

    Leo

    (@leohsiang)

    Hi there,

    Weird I thought I’ve replied to this.

    When I visit the linked page, I don’t see the main navigation, and also the HTML for the main navigation is also removed. So the code is working?

    Thread Starter FeliceAntonio

    (@antonio_09)

    It works well to remove the Italian menu from the English section.
    But if I try to add the English menu inside return ''; doesn’t appear.
    I add HTML code:

    <nav id="mobile-menu-control-wrapper" class="main-navigation mobile-menu-control-wrapper">
    	<div class="menu-bar-items"></div> etc.
    • This reply was modified 3 years, 9 months ago by FeliceAntonio. Reason: corrige
    • This reply was modified 3 years, 9 months ago by FeliceAntonio.

    Hi there,

    I’m not exactly sure what’s the whole function involved.

    To clarify: Are you trying to replace the Italian with an English menu on English category?

    If that’s the case we can play around with wp_nav_menu_args filter.

    Say, for example, you have 2 menus and category names “English” and “Italian”.

    add_filter( 'wp_nav_menu_args', function ( $args ) {
        if ( 'primary' === $args['theme_location'] ) {
            if ( is_category('English') ) {
                $args['menu'] = 'English Menu';
            } if ( is_category('Italian') ) {
                $args['menu'] = 'Italian Menu';
            } 
        }
        return $args;
    } );
    Thread Starter FeliceAntonio

    (@antonio_09)

    @ejcabquina I thought the solution is more difficult, and for this, I didn’t think about two menus.
    I intended to add HTML code inside return ''; of function tu_move_navigation and was more complex I think.
    With your code and English Menu works very well!!!
    Always thanks you and all GP Team for first-level support -:)

    Nice one. Glad you got it sorted. No problem. ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change menu for a specific category’ is closed to new replies.