Welcome User / Welcome Guest Function (Mini-Hack)
This is a mini mod I came across while working on my child theme. I was looking to make my website more interactive, and so I needed a solution for when a guest visits the website, he would be greeted. Same concept goes for logged in users.
After searching on Google for a quick solution, I came across this article on the Wordpress Forum:
http://wordpress.org/support/topic/e...logged-in-user
Turns out, there's already such a function. Unfortunately when trying it out on my JobRoller Theme, nothing happened. It just echo'd Welcome Guest when I was logged in. After looking at the script closer, I realized that a small modification was needed. So 2 min later, the mod was done, reloaded the page, and it works! Thought I would share this with you guys if you're ever looking to do this.
Here's the Original Script (Works on Wordpress Blogs):
Code:
<?php global $user_nickname; get_currentuserinfo(); if ( $user_nickname<> "" ) { ?><?php echo $user_nickname ?><?php } else { ?>Welcome Guest<?php } ?>
Here's My Script (Works on JobRoller):
Code:
<?php global $userdata; get_currentuserinfo(); if ( $userdata<> "" ) { ?>Welcome <?php echo $userdata->user_login; ?><?php } else { ?>Welcome Guest<?php } ?>
So yeah, you can stick this pretty much anywhere on your website, header, sidebar, footer, pages etc. If you want to style it up, just wrap it with a div container or span container and style it up with css or just do what I do, stick it inside an h2 tag. lol.. Lazy bastard, I know..
Hope you find it useful in your projects.
Good Day.
-Alex