WP Tips – Different Message For Guest and Members


In today wordpress tip, I will show you how I go about showing a different message (or other things) for member and guest. The possibilities with this tip is endless. Is really is.

Lets begin with an argument in our head. If – a guess (non-member) is browsing on your site, display a “you are a guest” message. Else (member) is browsing on your site, display a “you are a member” message. Easy isn’t it.

These are two functions we could be using…

$user_level
$user_ID

Depending on how you want to control your content, they work very similar to each other.

$user_level has to do with the level of your account. If you own your site, then your user_level is 10, but if you are a guest or a subscriber your user_level is of course 0. WordPress treats guest and subscriber level equally. You can find out more about user_level or user_role at WordPress Codex

$user_ID is your placement in the user table of wordpress database. If you own your site, then your user_ID is of course 1. A guest user_ID is 0, and a member user_ID is depending on his placement when he registered.

Lets begin the code by calling the functions.

global $user_ID; $user_level;

the IF argument.

if( $user_ID >= 1 ) { // if user_ID is greater or equal to 1
You are a member...
}

the ELSE argument

else {
You are a guest...
}

That is it. You can see a live example on Idols Unlimited.

Advertisements
This entry was posted in WordPress. Bookmark the permalink.

2 Responses to WP Tips – Different Message For Guest and Members

  1. jan says:

    Good Site! Keep Doing That!l

  2. sweet-er says:

    Sorry, but what is mariburjeka?

    Jane.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s