add class to dropdown menu inside dynamic wordpress menu

江枫思渺然 提交于 2020-01-16 20:00:12

问题


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:


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.



来源:https://stackoverflow.com/questions/13671669/add-class-to-dropdown-menu-inside-dynamic-wordpress-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!