Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #206745

    What is the best way to add the user $display_name in the Header Menu

    Thanks,
    dnikitiuk

    #206763

    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

    #207004

    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

    #207011

    Hey Daniel!

    Put it in functions.php

    Best regards,
    Josue

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘How to add user $display_name to the Header Menu’ is closed to new replies.