The last version of WordPress provides a new toolbar in frontend view when you are logged in. To disable this feature you can add the following code in the functions.php
file in your active theme:
// Before check if the filter show_admin_bar exists
if( has_filter('show_admin_bar') ) {
add_filter( 'show_admin_bar', '__return_false' );
}
You’ll notice that the show_admin_bar
filter is not removed, but it is only disabled through the useful function __return_false()
:
/**
* Returns false
*
* Useful for returning false to filters easily
*
* @since 3.0.0
* @see __return_true()
* @return bool false
*/
function __return_false() {
return false;
}
In order to remove the show_admin_bar
filter, you may use remove_filter()
function. To do this, we must know the original function name hooked to the filter. But this is not always possible. So, a different way to realize the same result is:
wp_deregister_script( 'admin-bar' );
wp_deregister_style( 'admin-bar' );
remove_action('wp_footer','wp_admin_bar_render', 1000);
However, the code above will remove the admin bar from both backend and frontend. If you wish to remove the admin bar from frontend only, you may use:
// frontend?
if (!is_admin()) {
wp_deregister_script( 'admin-bar' );
wp_deregister_style( 'admin-bar' );
remove_action('wp_footer','wp_admin_bar_render', 1000);
}
You may also add a check for user:
// hide the bar for admin only, subscriber still see it
if (!is_admin() && !current_user_can('add_users')) {
wp_deregister_script( 'admin-bar' );
wp_deregister_style( 'admin-bar' );
remove_action('wp_footer','wp_admin_bar_render', 1000);
}
As usual, please don’t hesitate to leave any questions or comments in the feed below, and I’ll aim to respond to each of them.