WordPress (Sonny) Version 3.3 was released just last night. Half asleep, I downloaded the new version, set up the database, and installed it. A novel welcome method, I like it. Then I configured my settings the way I like it. Fix your banner, set up your permalinks (look, %postname%, awesome, awesome), format date and time, and more. Then I disabled the admin bar. Click "Update Profile." great! Hey, wait a minute. Is the admin bar still there? ? What [insert expletive]!
Why can't I get rid of the admin bar?
In new WordPress versions, the WordPress core developers decided that the admin bar is an important part of the admin section (from what I understand). Personally I don't think it's of much use. To me, it's just an ugly bar at the top of the page with only some options found on the side menu. No, I have an unbearable hatred of admin bars. I just don't like it.
With previous versions of WordPress, you could simply go to your user profile to disable the admin bar, or you could use this popular code in your functions.php file.
add_filter('show_admin_bar', '__return_false');
With the release of version 3.3, we no longer provide the option to disable the admin bar in the admin section. I applaud the WordPress core development team for trying to make WordPress easier to use and access, but something seems to be missing from their thinking. People like to have choices, but they don't like having those choices taken away from them. Especially when they use these options.
So, I quickly came up with this solution to disable the admin bar.
Disable admin bar in admin section
This code will be placed in the functions.php file, so go ahead and open it in your favorite text editor.
First let's set up the function by checking.
if (!function_exists('disableAdminBar')) { function disableAdminBar(){ } }
This will ensure that the function "disableAdminBar" does not already exist. If not, our function will run.
Next, let's remove the action that enables the admin bar.
if (!function_exists('disableAdminBar')) { function disableAdminBar(){ remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); } }
Now, for the action hook that initializes the disableAdminBar function.
if (!function_exists('disableAdminBar')) { function disableAdminBar(){ remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); } } add_filter('admin_head','remove_admin_bar_style_backend');
Okay, so this disables the admin bar, but still has 28 pixels of padding at the top of the page.
You can go into the admin-bar.css file and edit the css in it to remove the padding. The css property you want to edit looks like this.
body.admin-bar #wpcontent, body.admin-bar #adminmenu{ padding-top:28px; }
You can dig into the wp-admin.css file and change the css in it, but I think it's best to leave the core file alone. So I'm going to override the css in the function we just created. This is the function we will use to override the css.
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');
Here is the complete function to disable the admin bar and override the css.
if (!function_exists('disableAdminBar')) { function disableAdminBar(){ remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); 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'); } } add_filter('admin_head','remove_admin_bar_style_backend');
Now the 28px padding should be gone.
It's not pretty, but it works, and the css can be overridden this way too. If you want to re-enable the admin bar. You don't have to change core CSS back.
Disable admin bar in admin section
If you want to disable the admin bar on the front-end of your website, you can go into your user profile and uncheck "Show toolbar when viewing the site". Pretty simple, but if you want to disable the admin bar all together, we'll have to add more to the "disableAdminBar" function.
This is what disables the front-end admin bar.
remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
In our "disableAdminBar" function. It looks like this.
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() { echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>'; } add_filter('admin_head','remove_admin_bar_style_backend'); } } add_filter('admin_head','remove_admin_bar_style_backend');
The admin bar disappeared, but there was a problem. Your site now has a 28 pixel margin at the top.
This is tricky. This css is hardcoded in when "Show toolbar
when viewing site" is checked. I can't figure out how to remove the CSS so we have to override it like using the admin part of this function.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);
The 99 at the end of the add_filter hook is to ensure that the css in
is after the original hardcoded css inThis is our completed function.
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
in conclusion
This may not be the most convincing solution, but it works as a quick fix for now. I can’t wait to see what other solutions and WordPress tips are coming soon.
Well, WordPress version 3.3 (aka Sonny) is finally here. If you haven't upgraded yet, please upgrade now.
The above is the detailed content of Disable Admin Bar in WordPress 3.3: Step-by-Step Guide. For more information, please follow other related articles on the PHP Chinese website!

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
