Akhilesh
Akhilesh

Reputation: 1313

Add sub text in the wordpress menu

I want to add text here within the anchor tag of the wordpress menu. So the menu structure would be

<ul>
<li><a href="#">Item1<br>
<span class="sub-text">text here<span></a>
</ul>

The "Item1" and "text here" will be dynamic. That is it can be edited from the wordpress back end.

I am using the wordpress function wp_nav_menu to show the menu. Below is the code.

$defaults = array(
    'theme_location'  => 'primary',
    'menu'            => '',
    'container'       => false,
    'container_class' => '',
    'container_id'    => '',
    'menu_class'      => 'nav navbar-nav',
    'menu_id'         => '',
    'echo'            => true,
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '',
    'link_before'     => '',
    'link_after'      => '',
    'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth'           => -1,
    'walker'          => ''
);

wp_nav_menu( $defaults );

Please help.

Upvotes: 1

Views: 2279

Answers (1)

diggy
diggy

Reputation: 6828

You need a custom Walker to achieve that:

$walker = new Menu_With_Description;
wp_nav_menu( array(
    'theme_location' => 'primary',
    'walker' => $walker
) );

Tutorials all over the place on the web, e.g.: http://www.wpbeginner.com/wp-themes/how-to-add-menu-descriptions-in-your-wordpress-themes/

Upvotes: 2

Related Questions