Two methods for removing the Admin Bar from the top of WordPress without a plug-in

Source: Internet
Author: User
Tags comments php file wordpress logo

If the WordPress website administrator is not logged on, the Admin Bar will be displayed at the top of the front-end, which may affect the debugging and maintenance speed. Because many built-in JS or even external calls need to be loaded, it is better to remove them directly. Here, Lao Jiang certainly recommends the use of plug-ins.

METHOD. Deselect the check box on the user panel.

Remove the management toolbar from the top of WordPress

In our administrator user, you can select remove and save in the toolbar.

Method 2: modify functions. php

Directly add the script to the functions. Php file of the current topic:

The code is as follows: Copy code
Add_filter ('show _ admin_bar ',' _ return_false ');

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.