WordPress: Check if User is Logged In
Thanks for stopping by my personal blog on Marketing Technology! Over 50,000 visitors a month find my content worth returning for, so don't forget to subscribe to the Marketing Technology Blog RSS feed or to the Marketing Technology Email to have new content sent directly to your inbox. You may also find my other business blog helpful, Social Media Domination.
John Chow had a nice tip on his site today on posting an advertising link on your site and ensuring that it’s not indexed using nofollow. You can do this with a simple redirect page that John posts the code for.
I wanted to do this a little different. In my horizontal menu above, real estate is at a premium. I do have an admin link on there if I’m logged in… but for everyone else, that’s a blank spot. I decided, why not swap the content of that bar in the event it’s a visitor and not me? With WordPress, this is pretty simple:
<?php
get_currentuserinfo() ;
global $user_level;
if ($user_level > 0) {
wp_register(’<li class="menuitem">’,'</li>’);
} else {
echo "<li class=’menuitem’><a href=’/go/tla.html’ title=’Advertise on this Website’>Advertise</a></li>";
}
?>
I haven’t made a dime with Text Link Ads yet but I want to give it a good shot. It’s pretty inexpensive for my site… $35 per month and I get over 500 visitors a day. I look forward to serving some of these up!

Douglas Karr

Though I would I would revise the link it points to - now it asks you for your log-on details. Not the kind of page I wanted to be greeted with, if I were a prospective advertiser
/* If a browser has a user ID they must be logged in */if ( $user_ID ) :
echo “I am logged in”;
/* For everybody that doesn’t have one */
else :
echo “I am logged out / not logged in”;
endif;