• Hi everyone,

    I realize that I have been asking a lot of questions lately but I believe that this is one which could be of use to a great many WordPress users.

    Basically I want to put a username and user profile link at the top left corner of my website, https://www.corkstudentnews.com when the visitor is logged in.

    I’m sure you all know what I’m talking about, but just in case you don’t here’s a screenshot from another website, it’s what I’m trying to replicate:

    Example

    I guess that ‘User Profile’ would go in place of account.

    I also assume that this mod will be placed in header.php.

    It seems like it should be fairly complex, but would look great on WP sites if it could work.

    Hope that someone has a solution – I think it’s a tricky one!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter corkstudentnews

    (@corkstudentnews)

    Problem solved but I just wanted to show the answer in case anyone else was interested.

    Hi,<?php global $current_user;
    get_currentuserinfo();
    echo ‘User first name: ‘ . $current_user->user_firstname . “\n”;
    ?>

    would be the first bit.

    Thread Starter corkstudentnews

    (@corkstudentnews)

    For anyone who cares/ might find this useful for future reference, the complete code I inserted into the head is:

    <?php  if (is_user_logged_in()) {
              $user = wp_get_current_user();
              echo 'Welcome, <strong>'.$user->display_name.'</strong> ';
    
    echo  '| <a href="https://www.corkstudentnews.com/wp-admin/post-new.php" target="_blank">Write a Post </a>';
    
    echo  '| Edit  <a href="https://www.corkstudentnews.com/wp-admin/profile.php" target="_blank">user profile </a>';
    
    echo  '| <a href="https://www.corkstudentnews.com/wp-login.php?action=logout" >Logout</a>';
    
                            } else { ?>
              <b>Hi visitor!</b> Please <b><a href="https://www.corkstudentnews.com/wp-login.php?redirect_to=/">login</a></b>  to write a post</strong>
              or <b><a href="https://www.corkstudentnews.com/wp-login.php?action=register" target="_blank">register</a></b> to become a member.
              <?php } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Logged in as username — how to?’ is closed to new replies.