Support » Themes and Templates » Adding a user welcome to template header

  • Notice how at the top of this forum, if you are logged in, you see

    “Welcome, USER! View your profile » (Logout)”

    — that’s exactly what I want to put in my WordPress template, but I can’t figure out the right tags to do it. Any ideas?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Try putting this into your (template) sidebar or header:

    <?php if ($user_level > 0): ?>
    Welcome, <?php echo $user_nickname; ?>! <a href="<?php bloginfo('wpurl'); ?>/wp-admin/profile.php" title="View your profile">View your profile</a> » (<a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=logout" title="Logout">Logout</a>)
    <?php endif; ?>

    I pasted that code in my header and for some reason nothing shows up, not even in the source, as long as its inside that if. I don’t know PHP very well, so I don’t know what would keep it from working.

    It should never show up in the source, unless your webserver is broken. Have you pasted the code into your current template? Which one? Which file? Where did you put it?

    Here is the page. It should be at the top, right above the logo.

    Here’s my non-theme test page that I’m trying to imitate… check it out to see what I had. Everything is contained within a p tag with class “topline”.

    Thanks so much for helping me!

    I’m not familiar with the template you’re using but if it’s one of the many WP templates out there, I assume you have put the code here:


    Looking at your HTML source, it’s likely to be after the <div id="header"> and between the <p> and </p> tags. Is that right? If so, you should probably have the code enclosed in a <div> instead of a <p> tag.

    I don’t see the topline class in your source code, which leads me to believe that perhaps you didn’t put the code in the right file.

    Hey I couldn’t look at this yesterday. It’s right after <div id="header"> inside header.php. I changed it so all that code above is inside another <div> instead of a <p>.

    It still doesn’t seem to work. The odd thing is it looks fine if I just put in regular text w/o the PHP. Any ideas?

    BTW, it is a template I’m making for this newspaper that’s still in progress. Thanks!

    Try changing the initial line of pizdin’s code to:

    <?php global $user_identity; if ($user_identity): ?>

    Okay now it shows up when I’m logged in. The only problem is that it calls the user nickname to display. I can’t seem to find these user_ tags in the codex. (I’m looking here) Is there a place that lists these tags?

    Also: Is it easy to say if nobody is logged in, display something like Welcome | Register? Thanks so much!

    The $user_* are global variables, not tags. They are made global under many conditions in WordPress, especially after one runs the get_currentuserinfo() function. The variables that are scoped globally by it are generally:

    $user_login – login name pulled from cookie.
    $userdata – PHP oject includes all user profile data
    $user_pass_md5 = password encrypted in md5 hash;
    $user_identity = user’s selected display name;

    To change from the user nickname to something else (say their display name), look for:

    <?php echo $user_nickname; ?>

    and change it to:

    <?php echo $user_identity; ?>

    But whatever you choose, make sure to scope it to global first, as we do above to $user_identity.

    RE: Also…


    <?php endif; ?>

    to something like:

    <?php else : ?>
    <?php wp_register(); ?>
    <?php endif; ?>

    More on wp_register() template tag:

    Sweet! Thanks! Check it out:

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Adding a user welcome to template header’ is closed to new replies.