Skip to content
Advertisement

Removing admin menu links in wordpress using user ID

This is my code and I dont know why isnt working

add_action('admin_menu', 'hide_a_menu');
function hide_a_menu() {
    global $current_user;
    $user_id = get_current_user_id();
    if($user_id == '41') {
        remove_menu_page( 'edit-comment.php' );
    }
}

Advertisement

Answer

You misspelled the name edit-comment.php try the below code.

add_action('admin_menu', 'hide_a_menu');
function hide_a_menu() {
    global $current_user;
    $user_id = get_current_user_id();
    if($user_id == '41') {
        remove_menu_page( 'edit-comments.php' );
    }
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement