Forums

Looking for a plugin for "conditional menu" based on if user is logged in/out (3 posts)

  1. InterMike
    Member
    Posted 8 months ago #

    Hello! Does anyone know of a way to implement, or a plugin, that allows you to have conditional menus items - for example, to only display a menu item if a user is logged in or out? Been searching for a week for a plugin, but can't find one :(

    Thanks,
    Mike

  2. @mercime
    Member
    Posted 7 months ago #

    http://codex.wordpress.org/Function_Reference/is_user_logged_in
    which you can wrap around the whole UL or to one or so LI's in your menu

  3. InterMike
    Member
    Posted 7 months ago #

    Hmm, kinda works. I'm using BuddyPress, by the way. Too bad there isn't anything like Widget Context for menu items. I'm looking to add custom nav menu items like so:

    Mike
    - Edit Profile
    - Change Settings
    - Logout

    I've managed to add links to the menu with this:

    /** add custom nav menu items **/
    add_filter('wp_nav_menu_items','custom_nav_items',10,2);
    function custom_nav_items($menu, $args) {
        global $bp;
        $args = (array)$args;
        if ( $args['theme_location'] != 'primary' )
            return $menu;
        $customNav = '<li class="customNav"><a href="'. $bp->loggedin_user->domain .'">'. $bp->loggedin_user->fullname .'</a>
    	<ul class="sub-menu sub-menu-1">
    		<li class="subNav"><a href="'. $bp->loggedin_user->domain .'">'. $bp->loggedin_user->fullname .'</a></li>
    	<ul>
    </li>';
        return $menu.$customNav;
    }

    Is this okay, or is there a better way to do this? Also, how might I put conditions around sub nav items/dropdowns as well? Would the following work if placed before the dropdown?:

    if ( is_user_logged_in() ) {
        echo '<ul><li>Sub Nav Here</li></ul>';
    }

Reply

You must log in to post.

About this Topic