admin管理员组文章数量:1130349
I have a requirement and the requirement was, I need to remove some menu options from the front end WordPress admin bar after a user logged in. I have achieved almost all. Now I stuck up with the profile link. I need to display only admin bar and name of the user like Howdy "Ajay" (name of the user) and logout option only. The name of the user should not have any link. But the name of the user is having sitename/wp-admin/profile.php. So how can I remove this href link from the username. Any help would be greatly appreciated.
Below is my code to remove other menu items from admin bar:
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');
}
add_action('wp_before_admin_bar_render', 'remove_menuitems_from_admin_bar');
I have a requirement and the requirement was, I need to remove some menu options from the front end WordPress admin bar after a user logged in. I have achieved almost all. Now I stuck up with the profile link. I need to display only admin bar and name of the user like Howdy "Ajay" (name of the user) and logout option only. The name of the user should not have any link. But the name of the user is having sitename/wp-admin/profile.php. So how can I remove this href link from the username. Any help would be greatly appreciated.
Below is my code to remove other menu items from admin bar:
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');
}
add_action('wp_before_admin_bar_render', 'remove_menuitems_from_admin_bar');
Share
Improve this question
edited Oct 24, 2018 at 8:20
fuxia♦
107k39 gold badges255 silver badges461 bronze badges
asked Oct 24, 2018 at 6:44
user3408779user3408779
1035 bronze badges
2
- put some code that you tried or put the code that displays admin bar, so i can check and try to help. – Krishna Joshi Commented Oct 24, 2018 at 6:49
- I have updated my question, please check – user3408779 Commented Oct 24, 2018 at 6:53
1 Answer
Reset to default 1Try the below code,
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');
Hope this helps.
I have a requirement and the requirement was, I need to remove some menu options from the front end WordPress admin bar after a user logged in. I have achieved almost all. Now I stuck up with the profile link. I need to display only admin bar and name of the user like Howdy "Ajay" (name of the user) and logout option only. The name of the user should not have any link. But the name of the user is having sitename/wp-admin/profile.php. So how can I remove this href link from the username. Any help would be greatly appreciated.
Below is my code to remove other menu items from admin bar:
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');
}
add_action('wp_before_admin_bar_render', 'remove_menuitems_from_admin_bar');
I have a requirement and the requirement was, I need to remove some menu options from the front end WordPress admin bar after a user logged in. I have achieved almost all. Now I stuck up with the profile link. I need to display only admin bar and name of the user like Howdy "Ajay" (name of the user) and logout option only. The name of the user should not have any link. But the name of the user is having sitename/wp-admin/profile.php. So how can I remove this href link from the username. Any help would be greatly appreciated.
Below is my code to remove other menu items from admin bar:
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');
}
add_action('wp_before_admin_bar_render', 'remove_menuitems_from_admin_bar');
Share
Improve this question
edited Oct 24, 2018 at 8:20
fuxia♦
107k39 gold badges255 silver badges461 bronze badges
asked Oct 24, 2018 at 6:44
user3408779user3408779
1035 bronze badges
2
- put some code that you tried or put the code that displays admin bar, so i can check and try to help. – Krishna Joshi Commented Oct 24, 2018 at 6:49
- I have updated my question, please check – user3408779 Commented Oct 24, 2018 at 6:53
1 Answer
Reset to default 1Try the below code,
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');
Hope this helps.
本文标签: admin barHow to remove logged user profile href link
版权声明:本文标题:admin bar - How to remove logged user profile href link 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749237024a2337443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论