Then, refresh the page and you will see that the management tool on the top has been removed.
Method 3: Add Code
Put the following code in your topic's functions. php to completely remove the wordpress front-end management toolbar:
If (! Function_exists ('df _ disable_admin_bar ') {function df_disable_admin_bar () {// for the admin page remove_action ('admin _ footer', 'WP _ admin_bar_render ', 1000 ); // for the front-end remove_action ('WP _ footer ', 'WP _ admin_bar_render', 1000); // css override for the admin page function remove_admin_bar_style_backend () {echo '';} add_filter ('admin _ head', 'remove _ admin_bar_style_backend'); // css override for the frontend function remove_admin_bar_style_frontend () {echo '';} add_filter ('WP _ head', 'remove _ admin_bar_style_frontend ', 99) ;}} add_action ('init', 'df _ disable_admin_bar ');
Supplement:
Disable the top toolbar for all users and visitors
One line of code:
Remove_action ('init ',' _ wp_admin_bar_init ');
Display the top toolbar only for administrator users
If (! Current_user_can ('manage _ options ')){
Remove_action ('init ',' _ wp_admin_bar_init ');
}
Only display the top toolbar in the background
Maybe we don't need to see it when accessing the front-end.
If (is_admin ()){
Remove_action ('init ',' _ wp_admin_bar_init ');
}
Only display the top toolbar on the foreground
In contrast to the previous function, only an exclamation point is added ......
If (! Is_admin ()){
Remove_action ('init ',' _ wp_admin_bar_init ');
}
Removes the padding of 28px from the top toolbar.
There is still a blank section in front of the top toolbar of some blogs. You can delete it using the following code:
Function remove_adminbar_margin (){
$ Remove_adminbar_margin = '<style type = "text/css">
Html {margin-top:-28px! Important ;}
* Html body {margin-top:-28px! Important ;}
</Style> ';
Echo $ remove_adminbar_margin;
}
/* Wp-admin area */
If (is_admin ()){
Remove_action ('init ',' _ wp_admin_bar_init ');
Add_action ('admin _ head', 'remove _ adminbar_margin ');
}
/* Websites */
If (! Is_admin ()){
Remove_action ('init ',' _ wp_admin_bar_init ');
Add_action ('WP _ head', 'remove _ adminbar_margin ');
}
Remove the WordPress Logo from the top toolbar
Function remove_wp_logo (){
Global $ wp_admin_bar;
$ Wp_admin_bar-> remove_menu ('WP-logo ');
}
Add_action ('WP _ before_admin_bar_render ', 'remove _ wp_logo ');
Remove comments from the top toolbar
What is the comment prompt? It is the bubble on the right of the website name. You can turn it off if you don't need it.
Function remove_comment_bubble (){
Global $ wp_admin_bar;
$ Wp_admin_bar-> remove_menu ('comments ');
}
Add_action ('WP _ before_admin_bar_render ', 'remove _ comment_bubble ');
Remove the "new" button from the top toolbar
Function disable_new_content (){
Global $ wp_admin_bar;
$ Wp_admin_bar-> remove_menu ('new-content ');
}
Add_action ('WP _ before_admin_bar_render ', 'Disable _ new_content ');
Remove the "upgrade" button from the top toolbar
When a new version of the plug-in or theme is available, a prompt is displayed, which can be closed directly.
Function disable_bar_updates (){
Global $ wp_admin_bar;
$ Wp_admin_bar-> remove_menu ('updates ');
}
Add_action ('WP _ before_admin_bar_render ', 'Disable _ bar_updates ');
Add a button with links in the top toolbar
Function custom_adminbar_menu ($ meta = TRUE ){
Global $ wp_admin_bar;
If (! Is_user_logged_in () {return ;}
If (! Is_super_admin () |! Is_admin_bar_showing () {return ;}
$ Wp_admin_bar-> add_menu (array (
'Id' => 'custom_menu ',
'Title' => _ ('menu name'),/* the Name of the button */
'Href '=> 'http: // google.com/',/* change the link */
'Meta' => array (target => '_ blank '))
);
}
Add_action ('admin _ bar_menu ','m M _ adminbar_menu', 15 );
/* 15 after add_action is the button location. For details about the changes, see
10 = before WP Logo
15 = After WP Logo
25 = after the website name
100 = last */
Add a button with a slide link in the top toolbar