I thought I would add this as a quick follow on from my previous tutorial showing you how to make a login form in your WordPress sidebar (find it here), it used a technique to show a menu once a user had logged in.

So if you want to hide a menu from readers but show it to registered users you could use the following example:

Say you had a menu that looked something like this in your sidebar:

  • Registered User Menu

      Registered user menu options here!
  • If you only wanted registered users to be able to see and use this menu simply add <?php if ( ! is_user_logged_in() ){ ?> before the code above and of course close the php statement with <?php }?> at the end of it. Nice one now only registered, logged in users can see the menu!

    What if you need a menu that only appears to users of a certain level? Well can use another handy php staement. Place <?php if (current_user_can('level_10')){ ?> at the beginning of your menu code block and close it again with <?php }?>. This example will show the menu only to admins ‘level_10′ you can change this to suit whichever user level you want. Below is the standard wordpress user level list:

    Administrator: level_10
    Editor: level_7
    Author: level_2
    Contributor: level_1
    Subscriber: level_0 (although you would never use this as you could use is_user_logged_in() function)

    You can of course create your own user roles and levels using this plugin

    0

    One Response to “Menu only logged in users or certain users can see”

    1. Neil July 29, 2009 at 8:25 pm

      If you are also running Simple Press forum on your WP site then listen up!

      I came up with a quirky issue that took me a bit to figure out but is very simple.

      The issue is with the control panel menu that appears upon login. If the user is not an admin and they try and click on the New Post or Page link it takes them to the forum home page?

      The fix is in the Forum admin. Click on ‘Manage Options’ scroll down a bit and uncheck the option ‘Block User Access to WP Admin Pages’ headed by ‘WP Admin Pages Acces’.

      I should have known the problem fix was there as the forum links in with the wordpress user database.

    Leave a Reply

    Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Switch to our mobile site

    © 2012 Effutio - All Rights Reserved

    Perth Web Design - Free Web Host