WordPress Tip: Function is_user_logged_in

A PHP function is available in WordPress called is_user_logged_in that is very useful if you want to know if a user is logged in.  Why on earth would you want to know this?  Have you ever thought about adding custom content to your blog that only you can see or only logged in (registered users) can see?

If so this function is for you.  I recently updated my blog’s theme and realized that it has some space that could be used for secondary navigation.  nolinks1 The area in red seemed to me like a great place for additional links.

This is where the function is_user_logged_in can help me out.   In this case the area highlighted in red has its own div tag.  It currently looks like this:

<div id=”nav-space”></div>

Inside the div tag I place the following 2 lines.

<?php if (is_user_logged_in()){ ?>
<?php } ?>

The 2 lines call the function is_user logged_in and evaluate the return value with my if statement. The second statement simply closes or ends the if. Do not worry if you do not understand.  Let me just tell you what it does.

Suffice it to say that anything you put between the 2 lines will be seen by logged in users only. For this example I am going to insert a link.

<div id=”nav-space”>
<?php if (is_user_logged_in()){ ?>
<a href=”http://www.google.com”>Google</a>
<?php } ?>

In the example just above a link to Google will be placed in the red area above that can only be seen by a logged in user.  In this case, me!

Now let’s put it in to practice.    I have added 3 links to the red bar section.  I now have access to facebook, friendfeed, and twitter right in my header section. I like this.  I think I will add some additional links later.

Now remember they will only display if you are logged in.  If you are like me you mainly use the same computers and stay logged in.  As long as you are logged in you will see your links.

Do you hang out on your own blog alot?  Would you like to use your own blog for a mini portal? Do you have free navigation space available?

This is great for me and adds functionality for my purposes but leaves the blog crisp and clean for visitors.  Try this WordPress trick in your theme today.

Update Already

In this strange landscape that we call Web 2.0 a web app is born with few features but lots of promise. In the exciting but cliché “BETA” phase many changes take place. Rich features are developed to make the app a must use and must see. This is the most exciting time in the life of a web application where many changes and development take place.

Then comes the dreaded phase of a web application in which all resources are devoted to keeping the application running. This becomes a state where little or no development/enhancement takes place.

I understand full well the difficulty and pressures of keeping a web application running. Meanwhile investors and other onlookers ask and question profitability. Other pundits wonder about the applications strategy and potential for actually making money.

All of that makes sense to me in the big picture. However as a passionate end user invested in the application this “stay up phase” is very frustrating.

So the app has made it to the stay up phase, has a loyal following/user base of thousands or millions and loads of potential. We can call it the “rock solid app.”

Then bring on the competitors. Small start ups with little funding but lots of ideas start sprouting. The user base of our rock solid steady app is intrigued.

Why? Simply because of the phase change. The new start ups are shiny and new and in that cool “BETA” stage or even in “private BETA.” Development is occurring on a daily basis as the start ups develop and fine tune their feature sets.

The user base of the rock solid app user base may decline slightly but stays about the same. For it is rock solid and keeps running.

Time passes… more time passes… and more time passes… the rock solid app does nothing new to speak of but its up. No new features but hey it is running.

UPDATE Already!!! Meanwhile the blogosphere dreams up all sorts of enhancements for the rock solid app. The rock solid app can also pull ideas from the smaller start up competitors.

The rock solid app has the resources, plenty of ideas, and a large mostly loyal user base. But no new enhancements.

UPDATE Already!!! But the rock solid app is up and running.

This is the point in the post when I wanted to name the app. But the more I thought about it I know it applies to many. This is unfortunately very common. Update Already. Please?