Archived topic
conditional menus and search box in navigation
4 replies · Started by xdaniel on November 14, 2018
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
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 );
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
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 /> </span></a></li>';
}
return $nav;
}, 10, 2);
Thanks a lot
Daniel
No problem :)