¿Desea desactivar la barra de administración de WordPress para todos los usuarios excepto los administradores?
Por defecto, puede desactivar fácilmente la barra de administrador de WordPress para usuarios individuales. Sin embargo, esto puede llevar tiempo si tienes muchos usuarios registrados en tu sitio.
En este artículo, le mostraremos cómo desactivar fácilmente la barra de administrador de WordPress para todos los usuarios excepto los administradores.
¿Qué es la barra de administrador de WordPress?
Por defecto, WordPress muestra una barra de administrador en la parte superior de la pantalla para todos los usuarios conectados. Cuando acceda a su cuenta, podrá ver esta barra en el área de administrador de WordPress y en el resto de páginas.
La barra de herramientas de administrador de WordPress tiene atajos útiles a diferentes áreas de administración de WordPress, y estos atajos cambian en función del perfil del usuario y sus permisos en WordPress.
Sin embargo, la barra de administrador puede distraerle cuando está mirando la parte frontal de su sitio web.
También puede afectar al diseño de su sitio web y a la experiencia del usuario. Esto puede ser un problema si está creando o gestionando un sitio WordPress para terceros, ya que les impide ver el aspecto real de su sitio web.
Por suerte, hay varias formas de desactivar la barra de administrador para todos los usuarios excepto los administradores. Simplemente usa los enlaces rápidos de abajo para saltar al método que quieras usar:
Tutorial en vídeo
Si prefiere instrucciones escritas, siga leyendo.
Método 1: Desactivar la barra de administrador de WordPress para usuarios individuales
Puedes desactivar la barra de administrador para usuarios específicos simplemente editando su perfil de usuario. Este es un método rápido y fácil si sólo necesita eliminar la barra para un pequeño número de personas. Sin embargo, si tienes un sitio de membresía con muchos usuarios, te recomendamos que elijas otro método.
Para eliminar la barra de administrador manualmente, simplemente vaya a la página Usuarios ” Todos los usuarios en el escritorio de WordPress. A continuación, pase el ratón sobre el usuario que no necesita la barra de administrador y haga clic en “Editar” cuando aparezca.
Se abrirá el perfil de ese usuario.
Desde aquí, desmarque la casilla siguiente a la opción “Mostrar barra de herramientas al ver el sitio”.
A continuación, desplácese hasta la parte inferior de la pantalla y haga clic en “Actualizar usuario” para guardar los cambios. Esto desactivará la barra de administrador solo para esa persona específica.
Para ocultar la barra de herramientas a más usuarios, sólo tiene que seguir el mismo proceso descrito anteriormente.
Método 2: Desactivar la barra de administrador para todos los usuarios excepto los administradores (recomendado)
Si necesitas ocultar la barra de administrador para muchas personas, cambiar manualmente los ajustes de cada usuario te llevará mucho tiempo y esfuerzo.
Por esa razón, recomendamos desactivar la barra de administrador añadiendo código al archivo functions.php, que es un archivo de tema de WordPress. Si no has hecho esto antes, entonces marca / comprueba nuestra guía sobre cómo copiar y pegar fragmentos de código en WordPress.
Algunas guías le dirán que edite los archivos del tema manualmente, pero esto puede causar errores comunes de WordPress e incluso puede romper completamente su sitio web.
Por esa razón, recomendamos usar WPCode. Es el mejor plugin de fragmentos de código y facilita añadir código personalizado en WordPress sin poner en riesgo su sitio.
En primer lugar, deberá instalar y activar el plugin gratuito WPCode. Para más información, consulte nuestra guía práctica sobre cómo instalar un plugin de WordPress paso a paso.
Una vez activado el plugin, vaya a Fragmentos de código ” Añadir fragmento.
Aquí verás todos los fragmentos de código prefabricados que puedes añadir a tu sitio. Esto incluye un fragmento de código que te permite desactivar completamente los comentarios, subir tipos de archivo que WordPress no suele soportar, desactivar páginas de adjuntos y mucho más.
En la pantalla siguiente, debe pasar el ratón por encima de la opción “Añadir su código personalizado (nuevo fragmento)” y hacer clic en el botón “Usar fragmento” cuando aparezca.
En la siguiente pantalla, escriba un título para el fragmento de código. Esto es sólo para tu referencia, así que puedes usar lo que quieras.
A continuación, abra el menú desplegable “Tipo de código” y elija “Fragmento de código PHP”.
Una vez hecho esto, basta con pegar el siguiente código en el editor:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
Este código identifica a los usuarios que no son administradores y que no están viendo el panel de administración. Para estos usuarios, desactiva la barra de administrador de WordPress.
Después, desplácese por la página hasta la sección ‘Inserción’. Aquí, puedes mantener el método por defecto de ‘Auto Inserción’ para asegurarte de que el código se ejecuta en todas partes.
Por último, desplácese a la parte superior de la pantalla y haga clic en el carrusel / control deslizante “Inactivo” para que aparezca “Activo”.
A continuación, basta con hacer clic en el botón “Guardar fragmento” o “Actualizar” para que el fragmento de código pase a estar activo.
Ya está. Sólo recuerde marcar / comprobar su sitio web de WordPress para asegurarse de que todo funciona bien.
Método 3: Desactivar la barra de administrador de WordPress para todos los usuarios excepto los administradores (sin código obligatorio)
Si no quieres añadir código a tu sitio web, entonces puedes ocultar la barra de administrador usando un plugin. Hide Admin Bar Based on User Roles le permite quitar la barra de herramientas en función de los diferentes perfiles de usuario, por lo que esta es una buena opción si desea desactivar la barra para todos los miembros, clientes de WooCommerce, o algún otro perfil de usuario.
En primer lugar, debes instalar y activar el plugin Ocultar la barra de administrador en función de los perfiles de usuario. Para más detalles, consulta nuestra guía paso a paso sobre cómo instalar un plugin de WordPress.
Una vez activada, debe ir a la página Ajustes ” Ocultar barra de administrador. A continuación, marque / compruebe las casillas situadas junto a los perfiles de usuario en los que desea desactivar la barra de administrador.
Una vez hecho esto, basta con hacer clic en “Guardar cambios” para establecer los ajustes.
Método 4: Desactivar la barra de administrador para todos los usuarios (incluidos los administradores)
¿Desea desactivar la barra de administrador para todos los usuarios, incluidos los administradores del sitio?
Puede hacerlo añadiendo un código que desactive la barra de administrador para todo aquel que esté viendo las páginas públicas de su sitio. Esto significa que la barra de administrador solo aparecerá cuando estés en el escritorio de WordPress.
Para simplificar las cosas, WPCode tiene el fragmento de código exacto que necesitas en su biblioteca de fragmentos incorporada. Simplemente vaya a Fragmentos de código “ Biblioteca.
Aquí, busque ‘Desactivar la barra de administrador de WP’.
Cuando aparezca el fragmento de código adecuado, haz clic en su botón “Usar fragmento”.
El plugin añadirá automáticamente el código a su sitio, le dará un título descriptivo, elegirá el método de inserción correcto e incluso añadirá etiquetas para ayudarle a identificar el fragmento.
Este es el aspecto del código:
/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );
Ahora, todo lo que tiene que hacer es conmutar el interruptor de “Inactivo” a “Activo” y, a continuación, hacer clic en “Actualizar”.
Ahora, si visita la página principal de su sitio web mientras está conectado a su cuenta de WordPress, la barra de administrador desaparecerá.
Esperamos que este artículo te haya ayudado a aprender cómo desactivar la barra de administración de WordPress para todos los usuarios excepto los administradores. Puede que también quieras ver nuestra guía definitiva sobre seguridad en WordPress y nuestra comparativa de los mejores maquetadores de páginas de WordPress para crear estructuras / disposiciones / diseño / plantillas personalizadas sin código.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and 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.
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
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…
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?
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.