15

I need your help. I need to add a specific class on the link that wordpress generates in the menu. What should I edit? The HTML output in my case is:

<nav class="nav" role="navigation">
<ul>
<li id="menu-item-8" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8"><a href="example.com">Sample Page</a></li>
<li id="menu-item-9" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-9"><a href="http://example.com">Prova sample</a></li>
</ul></nav

the code in the header file that generate the menu is:

    <!-- nav -->
    <nav class="nav" role="navigation">
    <?php html5blank_nav(); ?>
    </nav>
   <!-- /nav -->

4 Answers4

31

You can do it through admin panel also

  • In Appearance > Menus, click the Screen Options tab

  • Under Show advanced menu properties, check CSS Classes

  • Now expand any menu item to reveal the CSS Classes (optional) text
    input.

  • Enter your class name and save your menu to apply the class to the
    menu item

http://sevenspark.com/how-to/how-to-add-a-custom-class-to-a-wordpress-menu-item

Raunak Kathuria
  • 3,185
  • 1
  • 18
  • 27
  • No problem, please accept the answer if it has solved your issue. It will help others if they come to view the question – Raunak Kathuria Dec 23 '13 at 23:22
  • 6
    The problem is that it hasnt solve my problem. I need to add a class to the element and with your tip it add the class to the
  • element.
  • –  Dec 24 '13 at 09:25