As in wordpress to edit a specific menu item?

There is a menu that is displayed using the function wp_nav_menu() dynamically. For example:

the <ul>
 the <li><a href="link1">Cars</a></li>
 the <li><a href="link2">home appliances</a></li>
 the <li><a href="link3">Microwave ovens</a></li>

Need to change/remove the value of the href attribute, ONLY the second menu item (link2) via PHP. The other links of the menu items remain the default as if they were output automatically. Which function is for this purpose? How to access to individual menu item.
March 23rd 20 at 18:40
2 answers
March 23rd 20 at 18:42
Cm. filter wp_nav_menu_objects.


add_filter('wp_nav_menu_objects', function ($items) {
 foreach ($items as $item) {
 if ($item->url == '') {
 $item->url = '';
 // Or the option to remove the link:
 // $item->url = null;
 return $items;
Thank you. What I was looking for. - giuseppe.Remp commented on March 23rd 20 at 18:45
March 23rd 20 at 18:44
A comprehensive guide menus, styles, hooks and Walker is on Kama (thanks to Timur and Dmitry).

Find more questions by tags WordPress