Forums

Write username outside the loop (9 posts)

  1. levani01
    Member
    Posted 3 years ago #

    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?

  2. 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!";
               };
    ?>
  3. levani01
    Member
    Posted 3 years ago #

    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)

  4. Hmm. I think it'd be this.

    echo('Hello, <a href="http://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 :/

  5. levani01
    Member
    Posted 3 years ago #

    Something is wrong in this code :(

    Parse error: syntax error, unexpected '<'

  6. levani01
    Member
    Posted 3 years ago #

    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 :)

  7. 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.

  8. levani01
    Member
    Posted 3 years ago #

    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?

  9. That's the URL I gave you before.

    http://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!

Topic Closed

This topic has been closed to new replies.

About this Topic