I have the WP3.4 and I would like to disable the admin bar. I have tried to do that with many ways, but the admin bar do not display. Is possible to do on this version of WP (3.4) or i make a mistake in the code?
Below are the ways that I’ve tried.
Thanks in advance.
The 1st :
function my_function_admin_bar(){
return false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
The 2nd :
add_action( 'init', 'disable_admin_bar', 1 );
function disable_admin_bar() {
add_filter( 'show_admin_bar', '__return_false' );
The 3rd
<?php
if (!function_exists('disableAdminBar')) {
function disableAdminBar(){
remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); // for the admin page
remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); // for the front end
function remove_admin_bar_style_backend() { // css override for the admin page
echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
}
add_filter('admin_head','remove_admin_bar_style_backend');
function remove_admin_bar_style_frontend() { // css override for the frontend
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_style_frontend', 99);
}
}
// add_filter('admin_head','remove_admin_bar_style_backend'); // Original version
add_action('init','disableAdminBar'); // New version
?>
You need to specify the order or number which signifies when the Hook gets fired. In this case I beleive it’s
0
and the filter is:wp_admin_bar_render
. The action to remove the function I believe is:The Function Reference:
Function Reference/remove action
And here it is in the core file:
WordPress Trac.
The simple front-end removal is via
show_admin_bar()
:This won’t affect admin, because it is considered non-removable there (was not when first introduced, but later changed to that approach).
is_admin_bar_showing()
is hardcoded to always return true on admin side and there is no “proper” way to remove toolbar there. Which is not to say it can’t be done, but that is probably shouldn’t be done.That’s a fast and right solution, but does not deactivate all requirements. For example, the scripts and styles are still active and have its load time. A complete solution in a small plugin as follows:
also as gist for download and forks.
I find the solution.
functions.php :
and the php file :
if the current user is not an admin or do not have administrative access
yourCHILDtheme/functions.php
Tested: WordPress 5+