PHP snippet · Admin & Dashboard

Hide the admin bar for non-admins

Hides the front-end admin bar for everyone below administrator, so customers and members see your design instead of a black bar over it.

About this php snippet

On any site with customer, member, or subscriber accounts, the admin bar sits over your design for people who have nothing to do with running it. They did not ask for it, and it tells them nothing they can use.

It also pushes the whole page down by 32 pixels, which quietly breaks sticky headers and full-height hero sections for logged-in visitors only. That is why it usually arrives as a report of an intermittent layout bug that nobody else can reproduce.

What it does

  • Hides the front-end admin bar for any user without the chosen capability
  • Keeps it for administrators
  • One capability value at the top of the snippet if you want the line drawn somewhere else

Good to know

  • Out of the box, the line is administrator, so everyone below it loses the bar
  • Switch the capability to the one editors hold, and authors and editors keep the bar too
  • wp-admin is untouched. This is the front-end bar only, so anyone who belongs in the dashboard still gets there normally.
  • Logged-out visitors never saw the bar in the first place, so nothing changes for them

More php snippets

Your EMCP guide

Answers from our docs

YOUR CHAT, YOUR CHOICE

Before we chat

MSR Builds processes your question and up to four recent messages on our server to answer from the EMCP docs. AI is optional and needs your separate permission.

The chat is kept in this page's memory, not saved as a conversation in our database or browser storage. Our hosting and security services process connection information, such as your IP address, to prevent abuse.

Cloudflare Turnstile checks your browser and connection to prevent automated abuse when you send a question. No login is required.

Please leave out personal, sensitive or confidential information, passwords and API keys.

You can withdraw consent and clear this page's chat at any time. This cannot undo a request already sent or erase provider/security records.

Chat privacy, retention & your rights ↗ · Privacy contact

Starting chat consents to this processing. You can browse our docs without using the chat.