Answer the question
In order to leave comments, you need to log in
How to add custom item to menu in wordpress?
The point is this. I would like to add my li to the end in the menu, in the frontend, in order to place a search string in it. I found one solution in the function file, everything works, but at the bottom of the site there is another menu where the last item should be different, and this search is added there too. looked at this function, but could not find any menu identifier there, in which you need to add an extra item.
Here is the code from function.
add_filter('wp_nav_menu_items','add_search_box', 10, 2);
function add_search_box($items, $args) {
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();
$items .= '<li class="menu-item">' . $searchform . '</li>';
return $items;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question