This snippet disables the WordPress admin bar (toolbar) on the frontend for all users. Useful for improving UI/UX on custom themes, client-facing websites where the admin bar is not needed.
/**
* Disable WordPress Admin Bar for all users
*
* Option 1
*/
add_filter( 'show_admin_bar', '__return_false' );
/**
* Disable admin bar for non-admin users
*
* Option 2
*/
add_action( 'after_setup_theme', function () {
if ( ! current_user_can( 'administrator' ) ) {
show_admin_bar( false );
}
});
/**
* Disable admin bar only on frontend
*
* Option 3
*/
if ( ! is_admin() ) {
add_filter( 'show_admin_bar', '__return_false' );
}