Remove the User Menu or Edit Profile or Logout Link from Top Admin Bar

Remove the user menu or edit profile or logout link from top admin bar image

Yea, sometimes users just don’t need easy access to their account… I mean, in most surveys, most users strongly agree that they prefer things to be as difficult as possible. So give ’em what they want! Hide the user menu or the edit profile menu… heck, even the logout link! Keep ’em locked up in your site forrreeeevvvvverrrrrrrrrr!

These are the keywords you can use to remove something.

What it does…

Removes items like Logout or Edit Profile from the top right User Menu. Or you remove the entire User Menu.

Why it does it…

Why not?! Well, lots of reasons why not. But the question is why… so… I don’t know.

Download JSON for importing into Code Snippets Pro
Download PHP for adding as a plugin or copying into functions.php

See the code…

<?php

// Admin Menu: Remove the User Menu or Edit Profile or Logout Link from Top Admin Bar
// https://snipsnip.pro/s/311
// For removing other items from the top menu bar, see here: https://snipsnip.pro/s/249
namespace WL86ed62;

function remove_usermenu_from_top_admin_menu() {
    // if you only want to remove it for certain users/roles you could do something
    // lik: get_current_user then check: if (in_array('editor',$user->roles)) {}
    global $wp_admin_bar;
	// remove the entire user menu container
    $wp_admin_bar->remove_menu('my-account');
}
\add_action( 'wp_before_admin_bar_render', '\WL86ed62\remove_usermenu_from_top_admin_menu' );