• Hi! First I apologize if this has been asked and answered; I searched and also read back about 5 pages of posts looking for an answer.

    I was wondering if it is possible to somehow use this custom menu to display a message in the menu that greets the user by their first name.

    For example, in the native WordPress admin toolbar, it says “Howdy, lovebugstudios!”

    I would like to do this same thing, and it looks like it could work if there’s a parameter to hook into(?). I’ve seen other plugins just reference it as “Howdy {first_name}” and it just works… but when I do this in the menu, instead of replacing the first name, it just displays it as if it were text so I get “Howdy, {first_name}”

    Am I missing something? Or does this plugin just not have this option?

    I am using WooCommerce, WooCommerce Memberships, Nav User Menu and the bridge plugin you wrote also.

    Thank you for your help!

    lb

Viewing 1 replies (of 1 total)
  • Plugin Author HelgaTheViking

    (@helgatheviking)

    Hi there. While adding a greeting to the menu is for sure possible, it’s not something this plugin does. The plugin controls who can/cannot see a menu item. That’s it.

    You probably need a small code snippet… something like this would be a start:
    https://wpbeaches.com/add-menu-items-in-a-certain-place-with-wp_nav_menu_filter/

    
    add_filter( 'wp_nav_menu_items', 'prefix_add_menu_item', 10, 2 );
    /**
     * Add Menu Item to end of menu
     */
    function prefix_add_menu_item ( $items, $args ) {
       if( $args->theme_location == 'primary' )
           $items .=  '<li class="menu-item">...</li>';
          } 
           return $items;
    }
    

    then coupled with some WP functions for getting the user, you could try the following snippet in your theme’s functions.php or via the Code Snippets plugin.

    
    /**
     * Add item to end of nav menus.
    
     * @param  string $items The html list items
     * @return string
     */
    function kia_add_greeting_to_of_menus( $items; ) {
    
    	if( $args->theme_location == 'primary' ) {
    
    		$current_user = wp_get_current_user();
    	 
    		if ( $current_user instanceof WP_User ) ) {
    
    	    	$name = $current_user->user_firstname ? $current_user->user_firstname : $current_user->user_login;
    	  
    			$greeting = '<li>' . sprintf( esc_html__( 'Hello, %s', 'your-text-domain' ), esc_html( $name ) )</li>';
    			$items = $items . $greeting;
    		
    	    }
    
    	}
    
        return $items;
    
    }
    add_filter( 'wp_nav_menu_items', 'kia_add_greeting_to_of_menus');
    

    I didn’t test this, so typos may exist. Definitely test on a staging site before using in production.

Viewing 1 replies (of 1 total)
  • The topic ‘Is it possible to use this to greet a user by name?’ is closed to new replies.