function remove_admin_bar_links () {
global $ wp_admin_bar;
$ wp_admin_bar-> remove_menu ('comments');
}
The above code will remove the COMMENTS link from the Admin Bar . The operation mechanism is based on the function $ wp_admin_bar-> remove_menu (ID) , by providing the ID of the path to be deleted (in this case the corresponding ID is COMMENTS ), you can completely remove any path from the Admin Bar.
Below is a list of some frequently used IDs and very useful for most of us:
- my-account-with-avatar / my-account: connecting to your account, here the ID parameter depends on whether the user is active or not to display the avatar.
- my-blogs: Sites menu, only works with Network mode.
- edit: link to edit posts or pages.
- new-content: add New menu.
- comments: connect to comments.
- appearance: Appearance menu.
- updates: update the path.
- get-shortlink: create a short path to any page.
2. Assign a custom path to WP Admin Bar:
To add your own links to the Admin bar menu, add the following lines of code in the functions.php file:
add_action ('wp_before_admin_bar_render', 'add_admin_bar_links');
function add_admin_bar_links () {
global $ wp_admin_bar;
$ wp_admin_bar-> add_menu (array (
'id' => 'Google',
'title' => __ ('Google'),
'href' => 'http://google.com'
));
}
According to the above example, we have added Google.com as a new path in Admin Bar, of course it can be adjusted to anything according to your requirements. The parameters to note here are id, title and href:
id: identification point of the path.
title: The name displayed on the Admin Bar.
href: the path address will point to.
For example, you can create submenu using the following code:
add_action ('wp_before_admin_bar_render', 'add_admin_bar_links');
function add_admin_bar_links () {
global $ wp_admin_bar;
$ wp_admin_bar-> add_menu (array (
'id' => 'Google',
'title' => __ ('Google'),
'href' => 'http://google.com'
));
$ wp_admin_bar-> add_menu (array (
'parent' => 'Google',
'id' => 'GoogleAnalytics',
'title' => __ ('Google Analytics'),
'href' => 'http://google.com/analytics'
));
}
The result will look like the image below:
3. Display the login form if the user is not logged in:
By default, the Admin Bar bar is only available for logged-in users. But for some reason, if you want this Admin Bar to always be displayed, and come with login templates if the user is not logged in, use WordPress Admin Bar Improved to enable this feature.
4. Turn off completely Admin Bar:
It sounds unreasonable, but many people want to completely remove this menu bar. Log in to the main WordPress panel and select the Profile tab. Under Show Admin Bar , uncheck chech at when viewing site and print dashboard:
If you are a multi-blog manager (or work in Network mode) and want to turn off the Admin Bar for all authors, add the following line of code in the functions.php file :
add_filter ('show_admin_bar', '__return_false');
Good luck!