S
S
Socrates2018-06-14 13:48:27
WordPress
Socrates, 2018-06-14 13:48:27

How to add custom li, a classes to wp_nav_menu?

The guys created their menu using:

register_nav_menus(
array(
    'top-menu' => __( 'Top Menu', 'blankslate' ),
    'bottom-menu' => __( 'Footer Menu', 'blankslate' )
  )
);

Called up the menu:
wp_nav_menu(array(
        'menu' => 'top-menu',
        'theme_location' => 'Top Menu',
        'depth' => 2,
        'container' => 'ul',
        'container_class' => ' ',
        'menu_class' => 'top-menu',
        'menu_id' => ' '
      ));

I can't figure out how to set custom classes for li, a elements?
I would be very grateful for the information!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Yanchevsky, 2018-06-14
@Karmov69

Well, either in Appearance -> Menu in the upper right corner, open Screen Settings, enable CSS classes and prescribe the necessary items, or select a filter.
For example try like this

add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);

function special_nav_class($classes, $item){
    $classes[] = 'your-custom-class';
    return $classes;
}

Video with examples .

A
anwebdev, 2019-11-03
@anwebdev

You can also use jQuery:
jQuery('#my_menu > li').addClass('my_class');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question