• Resolved freedealsandoffer

    (@freedealsandoffer)


    Hi,

    How can we achieve this functionality.
    1. For anonymous user, it should display Login and Register link in the header menu items.
    2. For Logged in user, it should display ‘Hello username’ instead of Login and Register button.

    We are having these links in the Primary Header Menu and intend to play in that area itself.
    Please help us out. Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’d like to know as well.

    Have you tried the UM log in widget?

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @freedealsandoffer

    You can try this code snippet ( add it to your theme’s function.php file or use the Code Snippets plugin to run the code ):

    
    add_filter( 'wp_nav_menu_items', 'um_062121_avatar_menu', 10, 2 );
    function um_062121_avatar_menu( $items, $args ) {
        
        if( ! function_exists("um_get_core_page") ) return $items;
        
        if( is_user_logged_in() ){
            $user_id = get_current_user_id();
            um_fetch_user( $user_id );
            $name = "Hello, ".um_user("display_name");
            $items = str_replace( '{um_user_login}', $name, $items );
            $items = str_replace( '#um_user_login_link', um_get_core_page("user"), $items );
        }else{
            $items = str_replace( '{um_user_login}', 'Login', $items );
            $items = str_replace( '#um_user_login_link', um_get_core_page("login"), $items );
        }
    
        return $items;
    }

    Now, you must create a Custom Link menu in the WP Admin > Appearance > Menu. Add this {um_user_login} as a Navigation Label. And then add this #um_user_login_link as a URL.

    Regards,

    • This reply was modified 3 years, 5 months ago by Champ Camba.
    Thread Starter freedealsandoffer

    (@freedealsandoffer)

    Thanks, it worked perfectly.
    Thanks for your prompt and accurate reply.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Welcome text in Primary menu for Logged in user’ is closed to new replies.