Viewing 7 replies - 1 through 7 (of 7 total)
  • I would like to know as well. I hope this is possible.

    I don’t think that this can be done with the Menu Item Visibility Control plugin because there isn’t a Conditional Tag based on the user.

    However, I just whipped together a code snippet that can handle this. Add it to your functions.php file.

    Change the number to the User ID that you want to target and change the theme location to the menu that you are targeting.

    Let me know if you have any questions.

    add_filter( 'wp_nav_menu_items', 'add_custom_link', 10, 2 );
    function add_custom_link( $items, $args ) {
    	$user_ID = get_current_user_id();
        if ($user_ID == "1" && $args->theme_location == 'primary') {
            $items .= '<li><a href="http://yourlink.com">Link Text</a></li>';
        }
        return $items;
    }
    Thread Starter iwrate

    (@iwrate)

    I found an easy solution… In the visibility section of the menu item, add one of the following conditionals.

    If you know the user id
    get_current_user_id() == 2;

    If you don’t know the user id, but know the username

    get_userdata(get_current_user_id())->user_login == ‘USERNAME’;

    @iwrate Even better! I didn’t realize that the plugin would accept a statement like that.

    Thread Starter iwrate

    (@iwrate)

    Yes. It’s working perfectly for us. Thanks for your help.

    get_userdata(get_current_user_id())->user_login == ‘USERNAME’;

    The code above works perfectly for one username. Any idea how to make it work for several usernames?

    Thread Starter iwrate

    (@iwrate)

    Sorry, I’m not a big WordPress coder, but I would think you could do it with OR statements (not sure how they do those) or something like user_login == (‘USERNAME1′,’USERNAME2’), but I’m not sure if that is supported.

    Good luck!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How do you show menu item to specific user?’ is closed to new replies.