[Support request] conditional menus and search box in navigation

Home Forums Support [Support request] conditional menus and search box in navigation

Home Forums Support conditional menus and search box in navigation

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #727399
    xdaniel

    Hello,
    as you suggested in some threads I worked with the conditional menus plugin.
    Now I ran into a problem. I activated two different menus and added the search box in the the navigation using the customizer. But it’s only in the first navigation bar and not in the second. How can I make this avaulable in both?
    Best, Daniel

    #727638
    Tom
    Lead Developer
    Lead Developer

    Since the conditional menu likely changes the name of the theme location, you could try this:

    add_filter( 'wp_nav_menu_items', function( $nav, $args ) {
        if ( $args->theme_location == 'NAME-OF-THEME-LOCATION-HERE' ) {
            return $nav . '<li class="search-item" title="' . esc_attr_x( 'Search', 'submit button', 'generatepress' ) . '"><a href="#"><span class="screen-reader-text">' . _x( 'Search', 'submit button', 'generatepress' ) . '</span></a></li>';
        }
    
        return $nav;
    } 10, 2 );
    #729021
    xdaniel

    Hello Tom,

    thanks for the reply. One question, how do I get NAME-OF-THEME-LOCATION-HERE? Is it the name of my menu?

    Best, Daniel

    #729095
    xdaniel

    Hello Tom,

    got it running using thís code:

    
    add_filter( 'wp_nav_menu_items', function( $nav, $args ) {
        if ( $args->theme_location == '' ) {
            return $nav . '<li class="search-item" title="' . esc_attr_x( 'Search', 'submit button', 'generatepress' ) . '"><a href="#"><span class="screen-reader-text">' . _x( 'Search', 'submit button', 'generatepress' ) . '<br />&nbsp;</span></a></li>';
        }
    
        return $nav;
    }, 10, 2);

    Thanks a lot

    Daniel

    #729146
    Tom
    Lead Developer
    Lead Developer

    No problem 🙂

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