| | |
Tech, Life, & Stuff…

A Blog by Franklin Pettit

January 24, 2009

Wordpress Tip: Function is_user_logged_in

Posted by : Franklin Pettit
Filed under : Blogging, Wordpress

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 } ?>
</div>

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.

7 Total TweetBacks: (Tweet this post)
  • en: To counteract pagan blood sacrifices, they performed a Christian (human) blood sacrifice and sprinkled salt? http://tr.im/CCzh Very witchy 10/22/09 01:26pm
  • en: how p. danny recalls mt ainslie. He seems to have thought a chuhuaua was a rottweiller and 100 supporters was 200 http://tr.im/CCzh 10/22/09 09:50am
  • en: New here? Best to reserve criticism http://is.gd/1xJEc psyblog offers a study with timely advice. 07/14/09 04:46am
  • en: This is heinous, no Olympic athlete should do this to his mouth.... http://is.gd/1xJEC 07/14/09 04:45am
  • en: REM - Three key indicators to pricing predictability. http://is.gd/1xprF 07/13/09 10:19pm
  • fpettit: Wordpress Tip: Function is_user_logged_in http://tinyurl.com/affh6p 01/25/09 01:51am
  • : He's good enough, smart enough, and doggonit, people elected him. 01/05/09 09:12pm

blog comments powered by Disqus

  • January 24, 2009 at 9:28 PM Franklin Pettit
    Stupid Permalinks...http://www.fpettit.com/2009/01/24/wordpress-tip-function-is_user_logged_in/

Add a comment on FriendFeed




About Franklin

I coined this blog "Tech, Life, & Stuff" for lack of a better description. This blog is primarily about my view on tech from South Carolina. I am a South Carolina software developer. More>

My Tweets

  • @Corvida your TweetSuite plugin is pointing to @admin change it to @Corvida in the options. :) 01/23/09 11:16pm
  • RT FriendFeed: My Content Portal & Aggregator http://tinyurl.com/c4v3gm from: @corvida 01/23/09 11:15pm
  • @corvida yeah. Target brand chips are resealable but those are the only ones that I know of. 01/23/09 07:00pm
  • It’s a Windows 7 Love Fest http://ff.im/-J2T9 01/23/09 06:55pm
  • Writing From Shower Thoughts [feedly] http://ff.im/-J2T8 01/23/09 06:55pm