Quantcast
Channel: WordPress Cheat Sheets » admin
Viewing all articles
Browse latest Browse all 39

How to Disable the Admin Bar in Your WordPress Site

$
0
0

In this tutorial I will show you how to disable the WordPress admin bar. The admin bar was introduced in WordPress version 3.1.

wordpress-admin-bar-screenshot

The WordPress admin bar is very helpful for quick access to the admin panel. For example, if you want to edit the page or post you are currently viewing , you can easily go to the edit mode with one click.

However, sometimes you may not want the admin bar on some of your WordPress sites. A perfect example of this is if you are running a membership site. You probably don’t want your members/users to see this admin bar and get confused by it.

How to disable Admin Bar

PHP Code Tweak

You just need to add some code in the functions.php file of your WordPress theme to disable the admin bar. The function to disable WordPress admin bar is show_admin_bar($bool);

As you can see this function needs a parameter which is a boolean type. This is a required value and must be true or false. If you pass false then it will prevent the admin toolbar from rendering on the front end of your site.

Insert the following code in you function.php file:

if(!function_exists(remove_admin_bar)){
    function remove_admin_bar() {
	if (!current_user_can('administrator') && !is_admin()) {
  	show_admin_bar(false);
	}
    }
    add_action('init', 'remove_admin_bar');
}

This will remove the admin bar for the general WordPress users. Only admin users will still be able to see the admin bar.

If you want to remove the admin bar for all users (including the admin users), you just need to remove the if condition from the above code. Here is an example snippet:

if(!function_exists(remove_admin_bar)){
    function remove_admin_bar() {
        show_admin_bar(false);
    }
    add_action('init', 'remove_admin_bar');
}

This will remove the admin bar for all user.

CSS Fix for the Admin Bar Area

After removing the header using the above mentioned code, some styling issue may occur (you may notice some extra margin and padding in the top of your site):

To fix this issue, add the following code to your “functions.php” file:

function remove_admin_bar_css() {
    echo '<style type="text/css" media="screen">
    html { margin-top: 0px !important; }
    * html body { margin-top: 0px !important; }
    </style>';
}
add_filter('wp_head','remove_admin_bar_css, 99);

You are all done! The admin bar will be fully removed from the front end after you apply the above mentioned tweak.

Note: There are some plugins out there that can disable the admin bar too.


Viewing all articles
Browse latest Browse all 39

Trending Articles