Deseja desativar a barra de administração do WordPress para todos os usuários, exceto os administradores?
Por padrão, é possível desativar facilmente a barra de administração do WordPress para usuários individuais. No entanto, isso pode levar algum tempo se houver muitos usuários registrados no seu site.
Neste artigo, mostraremos como desativar facilmente a barra de administração do WordPress para todos os usuários, exceto os administradores.
![How to disable WordPress Admin Bar for All Users except administrators How to disable WordPress Admin Bar for All Users except administrators](https://www.wpbeginner.com/wp-content/uploads/2021/01/how-to-disable-wordpress-admin-bar-for-all-users-except-administrators-og.png)
O que é a barra de administração do WordPress?
Por padrão, o WordPress mostra uma barra de administração na parte superior da tela para todos os usuários conectados. Quando você estiver conectado à sua conta, poderá ver essa barra de ferramentas na área de administração do WordPress e em todas as outras páginas.
![The WordPress admin bar The WordPress admin bar](https://www.wpbeginner.com/wp-content/uploads/2021/01/wordpress-admin-bar.png)
A barra de ferramentas de administração do WordPress tem atalhos úteis para diferentes áreas de back-end do WordPress, e esses atalhos mudam de acordo com a função e as permissões do usuário no WordPress.
No entanto, a barra de administração pode distrair quando você estiver olhando para o front-end do seu site.
Isso também pode afetar o design do seu site e a experiência do usuário. Isso pode ser um problema se você estiver criando ou gerenciando um site WordPress para terceiros, pois isso os impede de ver como o site deles realmente é.
Felizmente, há várias maneiras de desativar a barra de administração para todos os usuários, exceto os administradores. Basta usar os links rápidos abaixo para ir para o método que você deseja usar:
Tutorial em vídeo
Se você preferir instruções escritas, continue lendo.
Método 1: Desativar a barra de administração do WordPress para usuários individuais
Você pode desativar a barra de administração para usuários específicos simplesmente editando o perfil de usuário deles. Esse é um método rápido e fácil se você só precisa remover a barra para um pequeno número de pessoas. No entanto, se você administra um site de associação com muitos usuários, recomendamos que escolha um método diferente.
Para remover a barra de administração manualmente, basta acessar a página Usuários ” Todos os usuários no painel de administração do WordPress. Em seguida, passe o mouse sobre o usuário que não precisa da barra de administração e clique em “Editar” quando ele aparecer.
![How to edit a user's profile in WordPress How to edit a user's profile in WordPress](https://www.wpbeginner.com/wp-content/uploads/2021/01/editing-users-wordpress.png)
Isso abrirá o perfil do usuário.
A partir daí, desmarque a caixa ao lado da opção “Mostrar barra de ferramentas ao visualizar o site”.
![How to hide the admin toolbar for non-admin users How to hide the admin toolbar for non-admin users](https://www.wpbeginner.com/wp-content/uploads/2021/01/admin-hiding-toolbar.png)
Depois disso, role até a parte inferior da tela e clique em “Update User” (Atualizar usuário) para salvar as alterações. Isso desativará a barra de administração somente para essa pessoa específica.
Para ocultar a barra de ferramentas para mais usuários, basta seguir o mesmo processo descrito acima.
Método 2: desativar a barra de administração para todos os usuários, exceto os administradores (recomendado)
Se você precisar ocultar a barra de administração para várias pessoas diferentes, alterar manualmente as configurações de cada usuário exigirá muito tempo e esforço.
Por esse motivo, recomendamos desativar a barra de administração adicionando um código ao arquivo functions.php, que é um arquivo de tema do WordPress. Se você nunca fez isso antes, consulte nosso guia sobre como copiar e colar trechos de código no WordPress.
Alguns guias informam que você deve editar os arquivos do tema manualmente, mas isso pode causar erros comuns do WordPress e até mesmo danificar completamente o seu site.
Por esse motivo, recomendamos o uso do WPCode. Ele é o melhor plugin de snippet de código e facilita a adição de código personalizado no WordPress sem colocar seu site em risco.
Primeiro, você precisará instalar e ativar o plug-in gratuito WPCode. Para obter mais informações, consulte nosso guia passo a passo sobre como instalar um plug-in do WordPress.
Depois que o plug-in for ativado, vá para Code Snippets ” Add Snippet.
![Hiding the admin toolbar using WPCode Hiding the admin toolbar using WPCode](https://www.wpbeginner.com/wp-content/uploads/2021/01/wpcode-add-snippet.png)
Aqui, você verá todos os snippets pré-fabricados que pode adicionar ao seu site. Isso inclui um snippet que permite desativar completamente os comentários, fazer upload de tipos de arquivos que o WordPress normalmente não suporta, desativar páginas de anexos e muito mais.
Na próxima tela, passe o mouse sobre a opção “Add Your Custom Code (New Snippet)” e clique no botão “Use snippet” quando ele aparecer.
![Adding custom code to your WordPress website with WPCode Adding custom code to your WordPress website with WPCode](https://www.wpbeginner.com/wp-content/uploads/2021/01/custom-code-snippet.png)
Na próxima tela, digite um título para o snippet de código. Isso é apenas para sua referência, portanto, você pode usar o que quiser.
Em seguida, abra a lista suspensa “Code Type” (Tipo de código) e escolha “PHP Snippet”.
![Adding a PHP snippet to WordPress using WPCode Adding a PHP snippet to WordPress using WPCode](https://www.wpbeginner.com/wp-content/uploads/2021/01/adding-php-snippet.png)
Feito isso, basta colar o seguinte código no editor:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
Esse código identifica todos os usuários não administradores que não estão vendo o painel de administração no momento. Para esses usuários, ele desativa a barra de administração do WordPress.
Depois disso, role a página para baixo até a seção “Inserção”. Aqui, você pode manter o método padrão “Auto Insert” para garantir que o código seja executado em todos os lugares.
![Automatically inserting code into a WordPress website Automatically inserting code into a WordPress website](https://www.wpbeginner.com/wp-content/uploads/2021/01/wpcode-auto-insert.png)
Por fim, role até a parte superior da tela e clique no controle deslizante “Inactive” (Inativo) para que ele mostre “Active” (Ativo).
Em seguida, basta clicar no botão “Salvar snippet” ou “Atualizar” para ativar o snippet de código.
![Publishing a custom code snippet to WordPress Publishing a custom code snippet to WordPress](https://www.wpbeginner.com/wp-content/uploads/2021/01/publish-wpcode-snipppet.png)
É isso aí! Lembre-se de verificar seu site WordPress para ter certeza de que tudo está funcionando bem.
Método 3: Desativar a barra de administração do WordPress para todos os usuários, exceto administradores (nenhum código necessário)
Se você não quiser adicionar código ao seu site, poderá ocultar a barra de administração usando um plug-in. O Hide Admin Bar Based on User Roles permite remover a barra de ferramentas com base em diferentes funções de usuário, portanto, é uma boa opção se você quiser desativar a barra para todos os membros, clientes do WooCommerce ou alguma outra função de usuário.
Primeiro, você precisa instalar e ativar o plug-in Hide Admin Bar Based on User Roles. Para obter mais detalhes, consulte nosso guia passo a passo sobre como instalar um plug-in do WordPress.
Após a ativação, você precisa ir para a página Settings ” Hide Admin Bar Settings. A partir daí, marque as caixas ao lado das funções de usuário em que deseja desativar a barra de administração.
![Hiding the admin toolbar for specific user roles Hiding the admin toolbar for specific user roles](https://www.wpbeginner.com/wp-content/uploads/2021/01/hide-admin-role.png)
Feito isso, basta clicar em “Save Changes” (Salvar alterações) para armazenar suas configurações.
Método 4: desativar a barra de administração para todos os usuários (incluindo administradores)
Deseja desativar a barra de administração para todos os usuários, incluindo os administradores do site?
Você pode fazer isso adicionando um código que desabilita a barra de administração para todos que estão visualizando as páginas públicas do seu site. Isso significa que a barra de administração só aparecerá quando você estiver na área do painel do WordPress.
Para simplificar as coisas, o WPCode tem o trecho de código exato de que você precisa em sua biblioteca de trechos integrada. Basta acessar Code Snippets “ Library.
![The WPCode code snippet plugin for WordPress The WPCode code snippet plugin for WordPress](https://www.wpbeginner.com/wp-content/uploads/2021/01/code-snippet-library.png)
Aqui, procure por “Disable The WP Admin Bar” (Desativar a barra de administração do WP).
Quando o snippet correto for exibido, basta clicar no botão “Usar snippet”.
![The ready-made Disable The WP Admin Bar code snippet The ready-made Disable The WP Admin Bar code snippet](https://www.wpbeginner.com/wp-content/uploads/2021/01/wpcode-code-library.png)
O plug-in adicionará automaticamente o código ao seu site, dará ao código um título descritivo, escolherá o método de inserção correto e até mesmo adicionará tags para ajudá-lo a identificar o snippet.
Veja a seguir a aparência do código:
/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );
Agora, tudo o que você precisa fazer é alternar a chave de “Inativo” para “Ativo” e, em seguida, clicar em “Atualizar”.
![Adding custom code to WordPress Adding custom code to WordPress](https://www.wpbeginner.com/wp-content/uploads/2021/01/publishing-admin-snippet.png)
Agora, se você visitar o front-end do seu site enquanto estiver conectado à sua conta do WordPress, a barra de administração desaparecerá.
Esperamos que este artigo o tenha ajudado a aprender como desativar a barra de administração do WordPress para todos os usuários, exceto os administradores. Talvez você também queira ver nosso guia definitivo de segurança do WordPress e nossa comparação dos melhores construtores de páginas do WordPress para criar layouts de página personalizados sem nenhum código.
Se você gostou deste artigo, inscreva-se em nosso canal do YouTube para receber tutoriais em vídeo sobre o WordPress. Você também pode nos encontrar no Twitter e no Facebook.
Syed Balkhi says
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Destiny Boy says
This was very simple ans straight forward, it helped me
ronald osoo says
This code has bug , its working but not bullet proof . The normal user can by -pass this and get access to the user admin like panel at the top by just adding wp-admin/ to the url like trying to login
Math says
I agree, direct access to wp-admin/profile.php is making this useless.
Steve says
A lot of websites not only from wordpress have the same option. You can acces to the admin-login page of any website just writing example.com/admin : Thats normal. I find it’s look really good without the adminbar.
Alex S says
Hello,
I wish your syntax highlighter was better. Tried to copy the code and got the numbers starting at 2. I don’t need your numbers, just the good code. I would use this site a lot more if this was not the case.
Thanks.
WPBeginner Support says
You can also click on the little button on top right corner of the code snippet. It will open the raw code in a popup, which is much easier to copy.
Administrador
stefano says
It works well, but the bar remains for visitors, who have not made the LOGIN
Jenn says
This plugin was working great and I was using Theme My Login. When I deactivated that plugin it is not not functioning as before… I see the admin bar for all users. Any suggestions?
Jenn says
Sorry I meant to say this ‘code’ was working great. I created a site-specific plugin as well and everything was working great. But after deactivating Theme My Login, not it seems to not have any effect and I see the admin bar on all users.
Suggestions?
Jenn says
I just tried adding in the code for all users: show_admin_bar(false); and I can still see the admin bar.
Alexander Pardo says
Thank you very much ! A very simple and clean solution.![:)](https://www.wpbeginner.com/pt/wp-content/plugins/classic-smilies/img/icon_smile.gif)
Jason A. Churchill says
I’m not well-read in editing the functions.php file. My first two attempts resulted in syntax error messages.
Where exactly should I place this code in the functions.php file?
WPBeginner Support says
At the end. If your functions.php file ends with ?> then you need to paste the code just before it.
Administrador
Terry Hale says
Thanks so much for this! No plugins, nice, clean, simple.
WPBeginner Staff says
WordPress admin bar is displayed only for logged in users.
Bhris says
Great straight-to-the-point tutorial.
Is there a version of the code that will block all non-users. That is, visitors to the site won’t see the bar, while all logged-in users would?
Shashi says
I was trying to do what what was mentioned in the article and it did not work. I used the following instead which did the trick from me:
if ( ! current_user_can( ‘manage_options’ ) ) {
show_admin_bar( false );
}
The above was mentioned in the wordpress codex: http://codex.wordpress.org/Function_Reference/show_admin_bar
vipin says
Thanks a lot its really cool…………
Karen says
Neither worked for me. I copied the numbers with the text as I did not know that I could![:-(](https://www.wpbeginner.com/pt/wp-content/plugins/classic-smilies/img/icon_sad.gif)
click on the button on top right corner of the code snippet and copy the raw code. I removed the numbers, but overlooked the seven. I had to change the file entry in via my file manager as I could no longer edit the functions.php. So after a scare and a bit of back and forth I removed the number and the admin bar is still there. I also tried your code Shashi, but it’s not working either.
I have tried every plugin under the sun and nothing will remove the bar.
kim04099 says
Thank You!!
Che Boielle says
Fastest fix to an odd issue I’ve ever found and implemented. Great explanation simple to follow instructions. Thanks guys, will be book marking your site.
Manthan says
Thanks, Its the easiest way found..!!!
Ryan McGovern says
Thanks for the code snippet!
Anup says
Why not simply do this for any specific user.
Jack says
It would be hard to do this if you have many users.
Róger Marroni says
Great job man!
thank you very much!
Mega says
I tried and my site is black.
Ryan S says
the first step works fine, it is something in your end, maybe while implementing the code
Etienne says
Perfect piece of code… Thanks a lot!
Cheers
Nathan Jansen says
Use this if you want this only for a certain role
function remove_admin_bar() {
$user = wp_get_current_user();
if (in_array(‘subscriber’, $user->roles)) {
show_admin_bar(false);
}
}
meef says
Godbless You. Answers to my problem always come from you post.
Thanks
Prem says
Finally I got the answers Thank you
Paw Pet Directory says
I used this on my directory for my customers but the bar will not go away for them. I am using 3.8 with AppThemes Vantage Theme (Latest)
Cory says
This is one of those things that, because it’s such a small customization, I’d hate to use a plugin for. So being able to throw this short piece of code into my child theme’s functions.php made me super happy. Thanks so much far sharing! Works like a charm.
Raman says
Thanks for posting it was useful.
Naveen says
I have added this code it is working fine, but if a user takes meta there is an option yo view the admin, if i click on this the admin page can see, how to avoid this, i dont want to give admin panel to the users, a user can edit the url and give /wp-admin also he can see the admin, i dont want both what will do for this?
Subodh says
Admin bar is hidden but now how can a user log out?
I am using bbpress forum and a plugin for users to log in via their Facebook account to join forum. But find no option for logging out.
WPBeginner Support says
A link to the logout or login can be provided into sidebar or menus. WordPress comes with a default widget called meta which has login/logout link. Or you can add one to your site’s navigation menus. See our guide on how to show different menus to logged in users
Administrador
Loralee says
Thanks for the great tutorial. I thought it didn’t work – and then silly me I hadn’t followed the last step to activate my new plugin!! Thanks so much for this! So much better than installing multiple new plugins.
vikas says
Thanks mate….u were really helpful…![:-)](https://www.wpbeginner.com/pt/wp-content/plugins/classic-smilies/img/icon_smile.gif)
tc
Rajat says
Thx syed it just worked perfectly
Bongo says
Thanks for this, it helped me a lot
Andy Wagstaff says
I have an area of my site that requires log-in registration.
I have made the admin bar “autohide” by requiring a plug-in, I don’t want to entirely disable it, as I need the abiity to change password, but is there any way of removing items from the bar for users? I don’t want the site name,WP logo or the theme extensions options on the left hand side.
Is this possible? I am sure it is, but I can’t work it out!!
Ta!! Really handy site by the way
Andy
Rajiv says
Hi,
I want to disable BP Admin Bar for Logged Out Users.
Please help.
Ken Shoufer says
Hello,
Your code worked fine when I tried it locally on my computer, but when I tried it on a fresh WordPress install on my host server it would not let me log out. When I tried to log out, the address showing was “http://www.ken-shoufer.com/wordpress1/wp-login.php?action=logout&_wpnonce=9e7f51a307”.
I’m not sure what is wrong.
Editorial Staff says
That’s weird because we have it running on our live site.
Administrador
Adrian says
Thanks!
Fabio Santos says
You can use this nice plugin instead: http://wordpress.org/plugins/global-admin-bar-hide-or-remove/
Nate says
i am trying to disable the W logo on the top left, the “My Sites” menu and the dashboard link on a buddypress multisite install. I want to keep the right side functional which shows the links to their buddypress profile settings. How can I achieve this?
Tanner Moushey says
To avoid the blank space where the admin bar was, call the function in the “after_setup_theme” action instead of “init”.
Cristian O. Balan says
Really perfect, thanks a lot!
Will says
Thank you so much! This worked perfectly and resolved several hours of head-scratching.
Cristian B. says
Really nice code. Are here also a fix to the blank bar that many here complains?
David says
Hi,
To avoid the blank, just instead of :
add_action(‘init’, ‘remove_admin_bar’);
use:
add_action(‘after_setup_theme’, ‘remove_admin_bar’);
Cristian O. Balan says
Thanks a lot man!
niki says
Fantastic! Except I also have the blank space visible where the admin bar would be. Does anyone have a fix for this?
Marlita Hill says
Hello. Thank you for this. How would I write the code if I only want the bar accessible to admin and contributors? I still do not want the contributors to have admin access to my backend.
Steve says
Well… it removes the admin bar but it´s still occupying the space meaning there´s too much space up there now. I´m not sure it´s supposed to be that way?![;-)](https://www.wpbeginner.com/pt/wp-content/plugins/classic-smilies/img/icon_wink.gif)
Adam says
worked …
Thanks a lot
Nick Cokas says
Add the code and worked perfect. However, the user still sees a white space above were the toolbar existed before. Any ideas to remove that.
Thanks
Toby Couchman says
Did you use a plugin to place all the necessary user stuff on the frontend?
My team recently built a site with similar requirements and I’d love to compare the processes.
Cheers
Toby
Mark Coleman says
Do not pass a role name to current_user_can(), as this is not guaranteed to work correctly. from
http://codex.wordpress.org/Function_Reference/current_user_can
just FYI
Editorial Staff says
Agreed. Just updated the code to make it into a function, and then adding it in via action.
Administrador
Sally says
Excellent post thanks so much!
Took me under a minute and the bar was gone… forever… truly grateful.
Sally
x
Corey Freeman says
Thanks to this I have one less plugin bloating my site. Woo!
Delton Childs says
This is an awesome post. short, to the point and contained a useful snippet! Thank you so much!
I’m using the S2Member plugin also, I was very concerned about compatibility issues with plugin based solutions because of the various s2Membership Levels. This solutions is working wonderfully for me.
Thanks Again!
James Davis says
Hi Guys,
Just found this bit of code and it worked perfect for my site…
Thanks so much
Cheers
James
AKA The Fitness Blogger
glueckpress says
Nice. For Superadmins in a Multisite install it would read like if(!current_user_can(‘manage_network’)) //etc.