Answer the question
In order to leave comments, you need to log in
How to add classes to menu in Wordpress?
There is a Menu on WordPress that
has a .menu class, I
hack the menu through wp in this way
<?php wp_nav_menu( array(
'theme_location' => '',
'menu' => '',
'container' => 'ul',
'container_class' => 'menu',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id = "%1$s" class = "%2$s">%3$s</ul>',
'depth' => 0,
'walker' => '',
) ); ?>
Answer the question
In order to leave comments, you need to log in
, but since the elements inside the menu also have classes, they are not styled
How to add classes to the elements inside the menu?
.menu li {}
, if you need to add another class to ul, you can add here 'menu_class' => 'new_class menu',
li $('.menu li').addClass('child');
example. Each menu item already has its own classes and id, and the selection can be done as you like. What is the problem? <?php wp_nav_menu( array(
'theme_location' => '',
'menu_class' => 'menu',
) ); ?>
Hello.
To do this, you need to create a Walker.
If you have a bootstrap theme, then the finished walker is here - https://github.com/wp-bootstrap/wp-bootstrap-navwalker
If you want to get a clean walker and then style it, then https://gist.github.com /thefuxia/1053467
Create a PHP file, add the code above, make an include via functions.php
Style it to your liking. And do not forget to specify walker in the displayed menu (pay attention to the last line of your code where you need to specify walker)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question