Skip to content

Instantly share code, notes, and snippets.

@bagerathan
Created August 27, 2021 07:19
Show Gist options
  • Save bagerathan/5af44a667ed6751febc6631bedefc186 to your computer and use it in GitHub Desktop.
Save bagerathan/5af44a667ed6751febc6631bedefc186 to your computer and use it in GitHub Desktop.
[Add anything to menu] #wp
//add search to menu
function add_last_nav_item($items, $args) {
if ('menu' == $args->theme_location) {
$searchblock = get_search_form(false);
$items .= '<li><svg class="menu-search" xmlns="http://www.w3.org/2000/svg" width="21.472" height="20.171" viewBox="0 0 21.472 20.171"><path d="M29.053,20.3a8.766,8.766,0,0,0-8.525,6.033,8.089,8.089,0,0,0,3.877,9.351,9.252,9.252,0,0,0,10.613-1l6.144,5.782.5-.471-6.108-5.782a7.933,7.933,0,0,0,1.576-8.956A8.861,8.861,0,0,0,29.053,20.3Zm0,15.935A7.881,7.881,0,0,1,20.944,28.6a7.881,7.881,0,0,1,8.109-7.631A7.881,7.881,0,0,1,37.162,28.6,7.881,7.881,0,0,1,29.053,36.235Z" transform="translate(-20.191 -20.3)" fill="#fff"/></svg>'.$searchblock.'</li>';
return $items;
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_last_nav_item', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment