请尝试以下代码,
function remove_menuitems_from_admin_bar() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(\'wp-logo\');
$wp_admin_bar->remove_menu(\'user-info\');
$wp_admin_bar->remove_menu(\'site-name\');
$wp_admin_bar->remove_menu(\'dashboard\');
$wp_admin_bar->remove_menu(\'edit-profile\', \'user-actions\');
$wp_admin_bar->remove_menu(\'my-account\');
$user_id = get_current_user_id();
$current_user = wp_get_current_user();
if (!$user_id)
return;
$avatar = get_avatar($user_id, 26);
$howdy = sprintf(__(\'Howdy, %s\'), \'<span class="display-name">\' . $current_user->display_name . \'</span>\');
$class = empty($avatar) ? \'\' : \'with-avatar\';
$wp_admin_bar->add_menu(array(
\'id\' => \'my-account\',
\'parent\' => \'top-secondary\',
\'title\' => $howdy . $avatar,
\'meta\' => array(
\'class\' => $class,
),
));
}
add_action(\'wp_before_admin_bar_render\', \'remove_menuitems_from_admin_bar\');
希望这有帮助。