9
Sep

WordPress Tutorial: How To Display A User Welcome Message

I believe that creating a great user interaction with your blog or website is key in keeping return visitors and helping with word of mouth advertisements and link love.

I know I’m not alone in this either because on almost every blog about marketing, blogging, and tutorials you find that the owners have added all of the extra plug-ins for their comments section, they’ve added in the “top commentators” and “most commented” plug-ins and sometimes use the LinkLove plug-in that will remove the nofollow attribute on commentators names after X amount of posts. So, what else is there that almost all blogs are overlooking that could help put them one step closer to creating the perfect user interaction?

Displaying A User Welcome Message

Some time ago I was reading a post over at WP Candy and it caught my eye. It was a tutorial on how to display content only to the site admin. This got me thinking and I even posted a quick reply there with a brief idea of what I’d like to do here today. I’m going to adopt the code from WP Candy, but please make sure you check out their website as well for the original article along with tons of other useful information.

First, we’re going to need to display the code below which will make sure the logged-in user is a level 0 which is the default level for members who have no power over anything other then leaving comments. This also allows any user level above 0 to see their username as well (ie: administrator level is 10, but they can still see this message as well). This also works well if you want to display a message for only a certain level of visitor (ie: admin, contributor, etc…).

< ?php global $user_ID; if( $user_ID ) : ?>
< ?php if( current_user_can('level_10') ) : ?>
< a href="http://www.yoururl.com/stats">Stats< /a>
< ?php else : ?>
< ?php endif; ?>
< ?php endif; ?>

Now, you can see the link code in the middle of this which links to a “stats” page. We’re going to remove that line and replace it with the code below which was found in the WordPress Codex. This code will display the name of the user who is currently logged into your website.

< ?php global $current_user; get_currentuserinfo(); echo ($current_user->user_login); ?>

Now that we have the new snippet of code added in, the full code should look like this:

< ?php global $user_ID; if( $user_ID ) : ?>
< ?php if( current_user_can('level_10') ) : ?>
< ?php global $current_user; get_currentuserinfo(); echo ($current_user->user_login); ?>
< ?php else : ?>
< ?php endif; ?>
< ?php endif; ?>

From here, you can modify what’s shown when the code echoes. Just add text before and after the echo code with any welcome message you’d like. For instance, I’ve added a couple full code snippets below which range from basic “Welcome back username” messages to a full blown welcome back message with links to various other pages of the site.

Simple Welcome Back Message

< ?php global $user_ID; if( $user_ID ) : ?>
< ?php if( current_user_can('level_0') ) : ?>
Welcome back < ?php global $current_user; get_currentuserinfo(); echo ($current_user->user_login); ?>
< ?php else : ?>
< ?php endif; ?>
< ?php endif; ?>

Welcome Back Message With An “in case you’ve missed these” Message And 5 Recent Posts

< ?php global $user_ID; if( $user_ID ) : ?>
< ?php if( current_user_can('level_0') ) : ?>
Welcome back < ?php global $current_user; get_currentuserinfo(); echo ($current_user->user_login); ?>. In case you’ve missed anything, here’s what we’ve recently posted.
<ul>< ?php wp_get_archives('type=postbypost&limit=5'); ?></ul>
< ?php else : ?>
< ?php endif; ?>
< ?php endif; ?>

Obviously for the above code, you can add a class or id to your ul tags or style them completely different. That’s totally up to you, but as you can see, the possibilities are unlimited. Below is a screenshot of how I’ve implemented this into my personal blog for the users who register to see a welcome back message.

The Welcome Back Admin is wrapped in an H3 tag and the style of the list follows the styling of the other lists in my sidebar.

wp-welcome-message

Your Turn To Talk

Feel free to expand on this and let me know in a comment if you have. I hope everyone enjoyed this tutorial. I am new to writing up tutorials like this, so bare with me if I’m not being in detail enough. If you have questions for me, feel free to leave a comment and I will reply to it for you. :)

jump to the comment form ↓

  • User Gravatar thom
    September 9th, 2009

    Thanks a lots for this tips. I’m curently building my new website and that could be very usefull with maybe jquery growl.

  • User Gravatar Derek
    September 10th, 2009

    Nice write-up. I don’t think you could have made it any easier :)

  • User Gravatar Andy Gongea
    September 10th, 2009

    For sure this approach will enhance the user experience. Great value and thanks for sharing, Mike.

    Cheers!

  • User Gravatar Ivan Mišić
    September 10th, 2009

    Nice tutorial

  • User Gravatar Ashely Adams
    September 19th, 2009

    That was some great tips Mike…..thanks. I would love to try them out. Keep posting

  • User Gravatar pankaj@theviewspaper
    October 8th, 2009

    Great post. it has been written in simple and lucid manner. Thanks a lot for great help .

  • User Gravatar Jim Hutchinson
    January 2nd, 2010

    Thanks for the great idea! I saw this mentioned on Twitter recently and changed it a bit before putting it to use. It now looks to see if there is a display name entered. If there is, the name is shown. Otherwise, the username is shown. All of it is wrapped in a box with the name in a different color than the rest so it stands out. I think this could prompt registered viewers to edit their accounts with a display name and check back more often because it is now more personal.

Who Linked To This Post?

  1. designfloat.com
  2. Wordpress Tutorial: How To Display A User Welcome Message | SpyreStudios
  3. Wordpress Tutorial: How To Display A User Welcome Message
  4. Wordpress Tutorial: How To Display A User Welcome Message | Web Design Updates
  5. links for 2009-09-09 | AndySowards.com :: Professional Web Design, Development, Programming Freelancer, Hacks, Downloads, Math and being a Web 2.0 Hipster?
  6. CSS Brigit | Wordpress Tutorial: How To Display A User Welcome Message
  7. tripwire magazine | tripwire magazine
  8. Wordpress Tutorial: How To Display A User Welcome Message | Design Newz
  9. 65+ Awesome Fresh Link for Designers and Developers | tripwire magazine
  10. Mes favoris du 10-09-09 au 11-09-09
  11. Best of the Web for the week of September 6, 2009 | designrfix.com
  12. Articles I’ve written elsewhere recently | Guerrilla Freelancing
  13. Very Useful 65 Wordpress Hacks | Design your way

Share your thoughts, leave a comment!