What is the best way to add the user $display_name in the Header Menu
Thanks,
dnikitiuk
Hi dnikitiuk!
You can use following code
add_filter( 'wp_nav_menu_items', 'avia_add_display_name_to_nav', 10, 2 );
function avia_add_display_name_to_nav( $items, $args )
{
if (is_object($args) && $args->theme_location == 'avia')
{
global $avia_config;
global $current_user;
get_currentuserinfo();
if(!empty($current_user->display_name)) $items .= '<li id="username-menu-item" class="noMobile menu-item">'.$current_user->display_name.'</li>';
}
return $items;
}
You can replace $args->theme_location == ‘avia’ with $args->theme_location == ‘avia2’ or $args->theme_location == ‘avia3’ if you want to add the name to another menu.
Best regards,
Peter
Hey Dude,
Thanks for the reply. In what location do I place this code; The navigation label of a menu item, or the quick CSS of the template?
I tired entering it in the navigation of the menu item but only received the code back for display.
Thanks,
Daniel
Hey Daniel!
Put it in functions.php
Best regards,
Josue