add class to dropdown menu inside dynamic wordpres

2019-09-10 15:07发布

I am pretty new to wordpress and am having trouble creating the primary navigation for the site.

I am using wp-nav-menu to output my dynamic menu.

The code I would like to output is the following...

<ul class="mainNav">
    <li><a href="">Home</a></li>
    <li class="dropdown">
        <a href="">Treatments<span>&#59232;</span></a>
        <ul>
            <li><a href="">Body Treatments</a></li>
            <li><a href="">Make Up</a></li>
            <li><a href="">Skincare</a></li>
        </ul>
    </li>
    <li><a href="">Latest News</a></li>
    <li><a href="">Aftercare</a></li>
    <li><a href="">Contact</a></li>
</ul>

The code I have used to get the menu above is this...

<?php wp_nav_menu( 
    array( 
       'menu'       =>  'Primary Navigation',
       'items_wrap' =>  '<ul class="mainNav">%3$s</ul>'
    ) 
); ?>

This gets me the main menu but I do not know how to get the <li> with the class of dropdown. I would also like to place a <span> inside one of the links, as you can see in my HTML code.

Any help would be greatly appreciated!

1条回答
再贱就再见
2楼-- · 2019-09-10 15:31

I have figured it out and will write it here in case anyone has the same problem.

In the wordpress admin, there is a link called screen options. Open this, and tick CSS classes, you can then add individual classes to menu items.

enabling css classes to nav_menu

查看更多
登录 后发表回答