SarahHidden Content for Registered Users

Written by Sarah from Stuff By Sarah

It can be quite useful to be able to add in links or information that you want either yourself, as an administrator, or your registered users to see, on the front end of your website.

The default template comes with user login/logout link, usually under the Meta Information section, but most people prefer to remove this as they don’t want login links to the general public. However, once you’ve logged in, why not give yourself a section of shortcut links to areas within your admin, or even display additional information or widgets, that you don’t want your visitors seeing?

If you’re the only one who logs into your site, or you want the hidden content available to every logged in user, then this is easily achievable using the is_user_logged_in() condition. All you need to do is use this with an if statement, and surround anything you want displayed to logged in users, for example, perhaps a link to the Admin, and a link to the Write Post page:

< ?php
if (is_user_logged_in()) :
?>
    <ul>
      <li><a href='/wp-admin/'>Admin</a></li>
      <li><a href='/wp-admin/post-new.php'>Write Post</a></li>
    </ul>
< ?php endif; ?>

You can place any HTML, or PHP code within the if statement, and anyone who is logged in will see it.

Multi Author Blogs

Whilst the above will show content to all logged in users, you may want to have additional information displayed just for yourself. You can achieve this by checking the Username of the logged in user, and comparing it against your own. To do this we can use

< ?php
if (is_user_logged_in()) :
    global $current_user;
    get_currentuserinfo();

    if ($current_user->user_login == 'admin') :
        // put any links or content just for the admin to see
    endif;
endif;

The above code first checks if the user is logged in, if they are then it gets their current user information, and compares their user login to the username of ‘admin’. You can change the username to your own username, if different.

Either of these methods can be used for shortcut links to your admin, displaying information for your eyes only, or displaying specific content to your registered users.

Follow this blogger on Twitter!

Sarah Written by Sarah from Stuff By Sarah
Posted on January 18th, 2009 and filed under WordPress Coding & Design
Do not forget to subscribe to our RSS feed for updates
  • Digg This Post
  • Tweet This Post
  • Stumble This Post
  • Submit This Post To Delicious
  • Submit This Post To Reddit
  • Submit This Post To Mixx
  • BloggingTips Uses Aweber

One Response to “Hidden Content for Registered Users”

Author comments are in a darker gray color for you to easily identify the posts author in the comments

Trackbacks

  1. [...] the full post at Hidden Content for Registered users on [...]

Comments are closed.

Comments are closed since this post is older than 30 days. However, you can continue this discussion in our popular Blogging Forums

Subscribe To BloggingTips Via RSS Subscribe To Blogging Tips Via Email Follow Us On Twitter Follow us on Facebook Find Out More About Our Newsletter

Sponsors

Blogging Tips Newsletter

Webmaster Corner

 

Our Free E-Books

Site Partners