Using PHP to Disable WordPress Admin Bar for All Users
By default, WordPress displays the admin bar at the top of the site for all logged‑in users. While useful for administrators, it may clutter the interface for other users. On ruachost.com, you can disable the admin bar globally with a simple PHP snippet.
Why Disable the Admin Bar?
Section titled “Why Disable the Admin Bar?”- Provides a cleaner front‑end experience for logged‑in users.
- Prevents non‑admin users from accessing admin shortcuts.
- Useful for membership sites or blogs where the admin bar is unnecessary.
Steps to Disable Admin Bar via PHP
Section titled “Steps to Disable Admin Bar via PHP”-
Log in to WordPress with an administrator account.
-
In the dashboard, go to Appearance → Theme Editor.
-
Select your active theme and open the functions.php file.
-
Add the following code snippet at the end of the file:
// Disable WordPress admin bar for all usersadd_filter('show_admin_bar', '__return_false'); -
Click Update File to save changes.
-
Refresh your site → The admin bar will no longer appear for any user.
Important Notes
Section titled “Important Notes”- Always back up your theme files before editing.
- Use a child theme to preserve changes during theme updates.
- This disables the admin bar for all users, including administrators.
- If you want to disable it only for specific roles (e.g., subscribers), you’ll need a conditional PHP check.