Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Move navigation search to the secondary navigation
add_action( 'after_setup_theme', function() {
remove_action( 'generate_inside_navigation', 'generate_navigation_search' );
remove_action( 'generate_inside_navigation', 'generate_mobile_menu_search_icon' );
add_action( 'generate_inside_secondary_navigation', 'generate_navigation_search' );
add_action( 'generate_inside_secondary_navigation', 'generate_mobile_menu_search_icon' );
remove_filter( 'wp_nav_menu_items', 'generate_menu_search_icon', 10, 2 );
} );
add_filter( 'wp_nav_menu_items', function( $nav, $args ) {
$generate_settings = wp_parse_args(
get_option( 'generate_settings', array() ),
generate_get_defaults()
);
if ( 'enable' !== $generate_settings['nav_search'] ) {
return $nav;
}
if ( 'secondary' === $args->theme_location ) {
$icon = generate_get_svg_icon( 'search', true );
return $nav . '<li class="search-item" title="' . esc_attr_x( 'Search', 'submit button', 'generatepress' ) . '"><a href="#">' . $icon . '<span class="screen-reader-text">' . _x( 'Search', 'submit button', 'generatepress' ) . '</span></a></li>';
}
return $nav;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment