I make a menu on the site through wp_nav_menu. WordPress site. WP automatically displays a menu with its own ul and li tags, and its classes. They don't suit me, tell me how you can either tie your classes to these tags, or print your own tags instead. I tried to replace the tags with my own - I achieved that there is no possibility to transfer the class to the tag. Original menu code:

<nav class="nav-menu"> <a href="#" class="nav-menu--link active-link">Главная</a> <a href="catalog.html" class="nav-menu--link">Продукция</a> <a href="about.html" class="nav-menu--link">О компании</a> <a href="contacts.html" class="nav-menu--link">Контакты</a> </nav> 

and the fact that I namudril in function:

 <nav class="nav-menu"> <?php wp_nav_menu( array( 'theme_location' => 'top', 'menu_class' => 'nav-menu', 'container' => 'false', 'items_wrap' =>'<a class="nav-menu--link active-link"> </a>', ) ); ?> </nav> 

Link to the long-suffering website: http://kaauto.volodysm.beget.tech/

Judging by what I read about the menu output mechanism - I will need to write my Walker, I looked at its source code - I realized that this is a bad idea. Tell me, please, solutions, the second day I'm already sitting ...

    2 answers 2

    The easiest way is to set classes right in the admin panel:

    enter image description here

    No need to move away from the menu structure of WordPress - through ul and li. This is the correct menu construction, especially when there are several levels of nesting. Anything you want can be made classes.

    • everything would be fine if it could be so. I have a theme created and when placing a mark in css classes - at the bottom of the additional field does not appear. it turns out you need to then edit functions.php Too much honor for the menu ... - Anton
    • That you thoroughly broke WP with your theme. I just checked on an absolutely empty topic, from scratch - if register_nav_menus() calls into functions.php, then the admin panel will be able to edit the menu and add css classes. I don’t even know what to do to prevent these classes from appearing. - KAGG Design
    • Can you throw off this topic? - Anton
    • Yes, there are two files in total. Here I described the topic of zero: ru.stackoverflow.com/questions/688720/… - KAGG Design

    The wp_get_nav_menu_items() function (documentation https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/ ) allows you to get all the elements of the specified menu and then work with them as you wp_get_nav_menu_items()