I want to add custom menu to my primary menu, I have used this below code for this,
add_filter( 'wp_nav_menu_items', 'search_menu_item', 10, 2 );
function search_menu_item ( $items, $args ) {
if ($args->theme_location == 'secondary-menu') {
$items .= '<li class="border-none">SEARCH<form><input type="text" name="s" placeholder="Search Here" class="search-box"></form>';
}
return $items;
}
and menu is appearing as a last menu, but I want to add my menu to 3rd position. How do I do this
Can anyone Help??
Thanks
You should rather use the wp_nav_menu_objects filter instead, which allows you to modify an array of items instead of a string.
Example:
Here are the steps to add custom menu in WordPress
You can call your menu wherever you want by just placing this one line code.
You can select arguments as per your need. Donât forget to include the name of the menu in the âmenuâ argument.