mirago
April 5, 2014, 9:44pm
1
Hello guys, I am trying to add description to wp_nav_menu, I have found that there is one way to do it like this
$item_html .= ' <span class="menu-desc">' . $item->description . '</span>';
Now what I want to do is I want to add that description to same <a></a>
tag and I am doing it like this
$item_description = '<span class="navbar-text visible-md visible-lg">' . $item->description . '</span>';
$item_html_new .= str_replace('</a>',$item_description.'</a>',$item_html);
$output .= $item_html_new;
It works fine but it doesn’t look very well for me, I am wondering is it a good way to do it? Or maybe you know a better way? Thanks and sorry for english mistakes if there is any !
shawn
March 4, 2015, 7:00am
2
Here’s a solution if anyone needs this in the future (for the Sage starter theme):
Go to ‘lib’ -> ‘nav.php’
Locate ‘function start_el(…) { ’ function section.
Add this IF statement inside the function:
// Add Description to Menu Item (inside anchor tag)
if (strlen($item->description) > 0 ) {
$item_html = substr($item_html, 0, -strlen("{$args->after}")) . sprintf(’%s ’, esc_html($item->description)) . “{$args->after}”;
}
Done
UPDATE:
This post helped… Resolved.
Rejoicing at first to have found a proper / simple solution for introducing descriptions for my menu items I was baffled to see that the current Sage install (8.2.1) doesn’t contain the nav-file any more…
shawn:
‘lib’ -> ‘nav.php’
What to do? Does this have to do with the step towards being framework agnostic ?
Looking forward to gaining some insight
Thanks + regards,
Henning