• Is there any code to write username outside the loop? If the user is logged in of course ??

    For example if the user is registered with username “myname”, when he logs in automaticaly write “hello myname”. How can I do it?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Something like this should work – THIS IS UNTESTED! – There may be simpler ways, natch.

    <?php  if (is_user_logged_in()){
               global $current_user;
               get_currentuserinfo();
               echo('Hello, ' . $current_user->user_login . "!\n");
             }
             else {
               echo "Welcome, visitor!";
               };
    ?>
    Thread Starter levani01

    (@levani01)

    Well it works fine! Thank you for help very much!

    And how to make the username linked to it’s profile page? (not on dashboard main page)

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Hmm. I think it’d be this.

    echo('Hello, <a href="https://www.domain.com/author/' . $current_user->user_login . '">' . $current_user->user_login . !</a>\n');

    My only worry is I may be having a stupid moment between ” and ‘ in the echo statement :/

    Thread Starter levani01

    (@levani01)

    Something is wrong in this code ??

    Parse error: syntax error, unexpected '<'

    Thread Starter levani01

    (@levani01)

    Well I corrected the code, it would be

    echo('Hello, <a href="wp-admin/profile.php">' . $current_user->user_login . !'</a>\n');
             }

    Ipstenu
    Thank you again for help ??

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    OH! You meant a link to edit the profile! Heh, I was thinking a link to view it. Glad it worked for you! Happy happy.

    Thread Starter levani01

    (@levani01)

    Is it possible that only view the profile without the ability to edit it? I have never heard anything about it. What does the page look like?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    That’s the URL I gave you before.

    https://www.domain.com/author/<name&gt;

    You may want to change <a href="wp-admin/profile.php"> to <a href="/wp-admin/profile.php"> by the way, or /blog/, depending on how you set up your blog, so that it will work from every page.

    And I see where I got the code wrong and why you had the unexpected <

    echo('Hello, <a href="/wp-admin/profile.php">' . $current_user->user_login . '!</a>\n')

    Put the ` on the left of the !, basically. I left it off my first example!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Write username outside the loop’ is closed to new replies.