i want to add a class to the a
tag of an sub-menu
and a b
tag inside the link.
WordPress gives me this code:
<li id="menu-item-72" class="menu-item menu-item-type-post_type menu-item-object-page dropdown menu-item-72"><a
href="#">Link</a>
<ul class="dropdown-menu"></ul>
And i want this:
<li id="menu-item-72" class="menu-item menu-item-type-post_type menu-item-object-page dropdown menu-item-72"> <a
href="#" class="dropdown-toggle" data-toggle="dropdown">Link <b class="caret"></b></a>
<ul class="dropdown-menu"></ul>
Does anybody know a solution for that?
Look at this answer, it explains how to add custom HTML to the wordpress menus: https://stackoverflow.com/a/12251157/1627227
EDIT:
I've put together an example to fit your question. You can place it into functions.php. Note the comments, they explain where to add your custom code.
After you have this in place, you have to go to the point where your menu (
wp_nav_menu()
) is called. In the answer I've linked to, there's the full function call towp_nav_menu
. However you'll have to add this line:'walker' => new Custom_Walker_Nav_Menu
to the arguments array, to use your custom walker object on that specific menu.Hope you got it ;)