Cart 0
Here is a code for how to disable WP Admin bar without using any plugins. Just copy the below code & paste your theme functions.php file. That’s all. Happy Coding.
Disable Admin Bar for everyone:
// Disable Admin Bar for everyone- www.sangvish.com 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 '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>'; } add_filter('admin_head','remove_admin_bar_style_backend'); // css override for the frontend function remove_admin_bar_style_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_action('init','df_disable_admin_bar');
Disable Admin Bar for everyone but administrators:
// Disable Admin Bar for everyone but administrators -www.sangvish.com if (!function_exists('df_disable_admin_bar')) { function df_disable_admin_bar() { if (!current_user_can('manage_options')) { // 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 '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>'; } add_filter('admin_head','remove_admin_bar_style_backend'); // css override for the frontend function remove_admin_bar_style_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_action('init','df_disable_admin_bar');