Volete disabilitare la barra di amministrazione di WordPress per tutti gli utenti tranne che per gli amministratori?
Per impostazione predefinita, è possibile disabilitare facilmente la barra di amministrazione di WordPress per i singoli utenti. Tuttavia, questa operazione può richiedere tempo se avete molti utenti registrati sul vostro sito.
In questo articolo vi mostreremo come disabilitare facilmente la barra di amministrazione di WordPress per tutti gli utenti tranne che per gli amministratori.
Che cos’è la barra di amministrazione di WordPress?
Per impostazione predefinita, WordPress mostra una barra di amministrazione nella parte superiore dello schermo per tutti gli utenti connessi. Quando si accede al proprio account, è possibile vedere questa barra nell’area di amministrazione di WordPress e in tutte le altre pagine.
La barra degli strumenti di amministrazione di WordPress contiene utili scorciatoie per accedere a diverse aree del backend di WordPress, che cambiano in base al ruolo e ai permessi dell’utente in WordPress.
Tuttavia, la barra di amministrazione può essere fonte di distrazione quando si guarda la parte frontale del sito.
Può anche influire sul design e sull’esperienza utente del vostro sito web. Questo può essere un problema se state costruendo o gestendo un sito WordPress per conto di terzi, in quanto impedisce loro di vedere l’aspetto reale del loro sito.
Fortunatamente, esistono diversi modi per disabilitare la barra di amministrazione per tutti gli utenti tranne che per gli amministratori. Basta usare i collegamenti rapidi qui sotto per passare al metodo che si desidera utilizzare:
Video tutorial
Se preferite le istruzioni scritte, continuate a leggere.
Metodo 1: Disabilitare la barra di amministrazione di WordPress per i singoli utenti
È possibile disattivare la barra di amministrazione per utenti specifici, semplicemente modificando il loro profilo utente. Si tratta di un metodo semplice e veloce se avete bisogno di rimuovere la barra per un numero limitato di persone. Tuttavia, se si gestisce un sito associativo con molti utenti, si consiglia di scegliere un metodo diverso.
Per rimuovere manualmente la barra di amministrazione, basta andare alla pagina Utenti ” Tutti gli utenti nella dashboard di amministrazione di WordPress. Passare il mouse sull’utente che non ha bisogno della barra di amministrazione e fare clic su “Modifica” quando appare.
In questo modo si aprirà il profilo dell’utente.
Da qui, deselezionare la casella accanto all’opzione “Mostra la barra degli strumenti durante la visualizzazione del sito”.
Quindi, scorrere fino alla parte inferiore della schermata e fare clic su “Aggiorna utente” per salvare le modifiche. In questo modo si disabilita la barra di amministrazione solo per quella persona specifica.
Per nascondere la barra degli strumenti a più utenti, basta seguire la stessa procedura descritta sopra.
Metodo 2: Disabilitare la barra di amministrazione per tutti gli utenti tranne gli amministratori (consigliato)
Se è necessario nascondere la barra di amministrazione per molte persone diverse, modificare manualmente le impostazioni di ciascun utente richiederebbe molto tempo e fatica.
Per questo motivo, consigliamo di disabilitare la barra di amministrazione aggiungendo un codice al file functions.php, che è un file del tema di WordPress. Se non l’avete mai fatto prima, consultate la nostra guida su come copiare e incollare frammenti di codice in WordPress.
Alcune guide vi diranno di modificare manualmente i file del tema, ma questo può causare errori comuni di WordPress e potrebbe addirittura distruggere completamente il vostro sito web.
Per questo motivo, vi consigliamo di utilizzare WPCode. È il miglior plugin per gli snippet di codice e consente di aggiungere facilmente codice personalizzato in WordPress senza mettere a rischio il sito.
Per prima cosa, è necessario installare e attivare il plugin gratuito WPCode. Per ulteriori informazioni, consultare la nostra guida passo-passo su come installare un plugin di WordPress.
Una volta attivato il plugin, andare su Code Snippets ” Add Snippet.
Qui vengono mostrati tutti gli snippet preconfezionati che è possibile aggiungere al proprio sito. Tra questi c’è uno snippet che consente di disabilitare completamente i commenti, di caricare tipi di file che WordPress di solito non supporta, di disabilitare le pagine degli allegati e molto altro ancora.
Nella schermata successiva, occorre passare il mouse sull’opzione “Aggiungi il tuo codice personalizzato (nuovo snippet)” e fare clic sul pulsante “Usa snippet” quando appare.
Nella schermata successiva, digitate un titolo per lo snippet di codice. Questo è solo un riferimento, quindi potete usare qualsiasi cosa vogliate.
Quindi, aprire il menu a tendina “Tipo di codice” e scegliere “Snippet PHP”.
A questo punto, è sufficiente incollare il seguente codice nell’editor:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
Questo codice identifica gli utenti non amministratori che non stanno guardando la dashboard di amministrazione. Per questi utenti, disattiva la barra di amministrazione di WordPress.
Quindi, scorrere la pagina fino alla sezione ‘Inserimento’. Qui si può mantenere il metodo predefinito ‘Auto Insert’ per assicurarsi che il codice venga eseguito ovunque.
Infine, scorrere fino alla parte superiore dello schermo e fare clic sul cursore “Inattivo” in modo che sia visualizzato “Attivo”.
Quindi, basta fare clic sul pulsante “Salva snippet” o “Aggiorna” per rendere attivo lo snippet di codice.
È tutto! Ricordatevi di controllare il vostro sito WordPress per verificare che tutto funzioni bene.
Metodo 3: Disabilitare la barra di amministrazione di WordPress per tutti gli utenti tranne gli amministratori (non è richiesto alcun codice)
Se non si desidera aggiungere codice al sito web, è possibile nascondere la barra di amministrazione utilizzando un plugin. Hide Admin Bar Based on User Roles (Nascondi la barra di amministrazione in base ai ruoli dell’utente ) consente di rimuovere la barra in base ai diversi ruoli dell’utente, quindi è una buona scelta se si desidera disabilitare la barra per tutti i membri, i clienti di WooCommerce o altri ruoli dell’utente.
Innanzitutto, è necessario installare e attivare il plugin Hide Admin Bar Based on User Roles. Per maggiori dettagli, consultate la nostra guida passo-passo su come installare un plugin di WordPress.
Dopo l’attivazione, è necessario andare alla pagina Impostazioni ” Impostazioni della barra di amministrazione nascosta. Da qui, selezionare le caselle accanto ai ruoli utente per i quali si desidera disabilitare la barra di amministrazione.
A questo punto, è sufficiente fare clic su “Salva modifiche” per memorizzare le impostazioni.
Metodo 4: Disabilitare la barra di amministrazione per tutti gli utenti (compresi gli amministratori)
Si vuole disabilitare la barra di amministrazione per tutti gli utenti, compresi gli amministratori del sito?
È possibile farlo aggiungendo del codice che disabiliti la barra di amministrazione per tutti coloro che visualizzano le pagine pubbliche del sito. Ciò significa che la barra di amministrazione apparirà solo quando ci si trova nell’area della dashboard di WordPress.
Per semplificare le cose, WPCode ha l’esatto frammento di codice di cui avete bisogno nella sua libreria di frammenti integrata. Basta andare su Code Snippets “ Library.
Qui, cercate “Disabilita la barra di amministrazione di WP”.
Quando viene visualizzato lo snippet giusto, fare clic sul pulsante “Usa snippet”.
Il plugin aggiungerà automaticamente il codice al vostro sito, gli darà un titolo descrittivo, sceglierà il metodo di inserimento corretto e aggiungerà persino dei tag per aiutarvi a identificare lo snippet.
Ecco come si presenta il codice:
/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );
A questo punto, è sufficiente spostare l’interruttore da “Inattivo” ad “Attivo” e fare clic su “Aggiorna”.
Ora, se visitate il front-end del vostro sito web mentre siete connessi al vostro account WordPress, la barra di amministrazione scomparirà.
Speriamo che questo articolo vi abbia aiutato a capire come disabilitare la barra di amministrazione di WordPress per tutti gli utenti tranne che per gli amministratori. Potreste anche voler consultare la nostra guida definitiva alla sicurezza di WordPress e il nostro confronto tra i migliori page builder di WordPress per creare layout di pagina personalizzati senza alcun codice.
Se questo articolo vi è piaciuto, iscrivetevi al nostro canale YouTube per le esercitazioni video su WordPress. Potete trovarci anche su Twitter e 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!
Hussam H says
Thank you and bless you.
WPBeginner Support says
You’re welcome!
Admin
Paul says
Using the after_setup_theme hook doesn’t always work. Try this instead:
function remove_admin_bar( $value ) {
return ( current_user_can( ‘administrator’ ) ) ? $value : false;
}
add_filter( ‘show_admin_bar’ , ‘remove_admin_bar’);
Matthew D Henderson says
Thank you for providing four different ways to do this. Perfect
WPBeginner Support says
Glad you found our recommendations helpful
Admin
Joey says
What would be the code if I want to add Editor and Admin to show the Admin bar..
if (!current_user_can(‘administrator’) && !is_admin())…
if (!current_user_can(‘editor’) && !is_editor())…
would it be if (!current_user_can(‘administrator’) && !is_admin() || !current_user_can(‘editor’) && !is_editor())
would this work?
WPBeginner Support says
For what you are wanting, you would want to remove: && !is_editor()
Then it should work how you are wanting.
Admin
Basia says
Hi,
I hide admin bar with plugin You recommend, but when subscriber log in he can still click on “view my profile” and see wp dashboard. Can I disable that?
WPBeginner Support says
You can redirect users after login using the method from our guide below:
https://www.wpbeginner.com/plugins/how-to-redirect-users-after-successful-login-in-wordpress/
Admin
Deewinc says
Thanks for the article but method 3 doesn’t work.
WPBeginner Support says
If method 3 is not working for you, we would recommend trying one of the other methods to test.
Admin
Dipesh Vedak says
what if theme upgrades?
WPBeginner Support says
If you created a site-specific plugin it would remain.
Admin
Brandon Porter says
Worked like a charm. Thank you!
WPBeginner Support says
You’re welcome, glad our guide was helpful
Admin
Bryan E Jackson says
Doesn’t seem to work for my Divi Theme
WPBeginner Support says
You may want to try clearing your cache for the most common reason for the change not being visible.
Admin
Paul says
What exactly does this disable? I still see an admin bar and I have access to menu options when I go to example.com/wp-admin when i’m logged into a subscriber account.
WPBeginner Support says
You would want to ensure the code was properly added for the most likely cause of the admin bar not being hidden otherwise, you could also have a plugin that would be overriding this code.
Admin
Jürgen says
Thanks. Just what I needed
WPBeginner Support says
Glad our guide was helpful
Admin
khaoula says
Thanks a lot ,but what to do if the user wants to logout ?
WPBeginner Support says
You can add a logout link to your menu for one option, we have a guide on how to do that below.
https://www.wpbeginner.com/wp-tutorials/how-to-add-the-wordpress-logout-link-to-navigation-menu/
Admin
Kaetech says
Thanks a lot. Just what I needed. It worked.
WPBeginner Support says
You’re welcome, glad our guide was helpful
Admin
Marc Korden says
Cannot add the admin code in my theme:
Communication with the site not possible to check for errors, the PHP adjustment has been reversed. The PHP file change needs to be changed in another way, for example using SFTP.
WPBeginner Support says
That message means that WordPress was not able to check the code for errors and you would need to use an FTP tool to add the code. We have a guide you can follow below:
https://www.wpbeginner.com/beginners-guide/how-to-use-ftp-to-upload-files-to-wordpress-for-beginners/
Admin
Jailson Pacagnan Santana says
Thanks! God bless you
WPBeginner Support says
You’re welcome, glad our guide was helpful
Admin
Ciao says
Where should i exactly insert the code, at the beginning, at the end of funcions.php? thx
WPBeginner Support says
We normally recommend at the end so it is easy to find and remove if needed
Admin
Agha Mubasher says
Hello there…!
First of all i simply love the work wpbeginner, as you always bring forward the simplest solutions to our wordpress issues. Your website and Youtube channel has always been helpful for me. Thumbs Up for that..
I had issue with hiding the admin bar for the subscribers only. Now after applying your code in the function.php it is hidden for my editors also.
Is there any way that my editors also can see the admin bar and only it should be hidden from the subscribers..!!
WPBeginner Support says
For that, you would need to target another permission that your editor has instead of what we are targeting such as edit_others_posts
Admin
Felix says
Thank you very much.
WPBeginner Support says
You’re welcome
Admin
Dana Jewel says
Thank you! This snippet has been really, really helpful.
WPBeginner Support says
You’re welcome, glad our guide could be helpful
Admin
Faris says
Great Help, It worked like a charm!
Thank You so much.
WPBeginner Support says
You’re welcome
Admin
Jesaja says
On my website it says:
“Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.”
What to do now?
WPBeginner Support says
It means the new WordPress safety features prevented you from editing the file, you would need to download and edit your theme’s files using FTP: https://www.wpbeginner.com/beginners-guide/how-to-use-ftp-to-upload-files-to-wordpress-for-beginners/
Admin
Jesaja says
Oh.. can’t I just put it in the Custom CSS area?
WPBeginner Support says
No, this is PHP not CSS so it wouldn’t go into there.
TaiRon says
It does work like a chame, your code is perfect but I have to change in file manager directly.
Thanks.
WPBeginner Support says
You’re welcome, glad our guide could help
Admin
Bongani says
Thanks , very useful tutorial
WPBeginner Support says
You’re welcome
Admin
Mike says
Thank you!
WPBeginner Support says
You’re welcome
Admin
Jim says
Can this code be altered to allow the WordPress Admin bar for Admins AND moderators, but hide it for everyone else?
Thanks!
WPBeginner Support says
You would need to add another && !current_user_can(”) inside the parentheses with the name of the role you are wanting it to appear on or use the plugin adminimize from our article: https://www.wpbeginner.com/wp-tutorials/what-everybody-ought-to-know-about-the-wordpress-admin-bar/
Admin
Andreas says
If a user knows the URL structure of WordPress he can easily browser to /wp-admin/ and there the admin toolbar will be visible. Also, the easiest way is to deactivate it in the user setting if you have a small number of users.
Adam Pressman says
Doesn’t work. Well, to be fair, works when you first use it but then something happens and it doesn’t anymore. nothing is overwriting the functions.php and the code is there but usually after the first login, logout cycle a subsequent login will see the admin bar return.
prashanth says
It works but user cannot logout. How to logout?
Cesar says
I have created a social media site using several plugins and everything works fine but for one issue. Pages are successfully restricted and redirected (Buddypress pages, blogs, etc) for non-logged in users.
However the main issue I am having is that non-logged in users can still have access to blog posts and user profile pages via widgets placed on side bar and footer and I cannot seem to find a solution anywhere.
Any ideas on the matter, plugins or code that I can insert in the child theme?
I have been looking for a solution for over a day and all there is there is how to restrict pages and partial content but nothing works on the widget links, they keep going thru the restrictions in place.
Thanks
WPBeginner Support says
Hey Cesar,
There are several widgets and plugins that allow you to hide widgets from non-logged in users. However, if non-logged in users know the URL, then they would still be able to access those URLs directly. You need to review your plugin settings and see if you can find the option to hide profile pages from non-logged in users.
Admin
Shabz says
This code or several others that I tried from the comments isn’t working. I’m trying to remove that dumb silver/black wordpress tab above my menu that shows up for all of my website’s users. How do I remove that? Please help
Humberto Buitrago says
Is there any plugin we can use instead code?
Thanks in advanced!
Jack Hernandez says
As mentioned in the article, you included a way for users to edit their profiles through the front end without the admin bar. How did you accomplish that.
Thanks
Paritosh Negi says
Thank you so much! <3 it works well
Chouchouda says
Hello, some issue , i have done everything but can’t hide toolbar for owner user in frontend , but can do this for admin user , incredible.
I’m using search& go theme wordpress , Thank for your help.
Alex says
Hello,
Code needs a little updating. This is the code I would use to redirect by role.
/*Hide admin bar for certain roles*/
function hide_admin_bar() {
if(is_user_logged_in() ) {
$current_user = wp_get_current_user();
if ( in_array( ‘subscriber’, (array) $current_user->roles ) ) {
add_filter(‘show_admin_bar’, ‘__return_false’);
}
}
}
Hope this helps.
Brandon says
Thanks for this updated code, Alex. Simple and works great.
Put it in child theme functions.php and forget about it.
Yuki Zain says
Thanks, Alex but I’m editing a bit
/*Hide admin bar for certain roles*/
if(is_user_logged_in() ) {
$current_user = wp_get_current_user();
if ( in_array( ‘subscriber’, (array) $current_user->roles ) ) {
add_filter(‘show_admin_bar’, ‘__return_false’);
}
}
randalf says
Very nice
but what do I do if I have two roles as a result of bbpress plugin.. That is registered users have the subscriber role in whole site and participant role in bbpress.
Please help
Scott says
Hi,
I inserted your code to remove the Admin bar from my membership site. Unfortunately it also removed it from me, the Admin (even thought I used your first option above). I am using the Tesseract Pro theme. Do you have any suggestions? Thanks
Inder Singh says
Dear Sir,
I have 2 admin user and i want to show admin bar for first user and remove admin bar for second user in wordpress.
How can i do it.
Thanks for support.
SG says
I tried using this and I got that code Parse error: syntax error, unexpected ‘}’ in /home/content/76/10323476/html/wp-content/themes/digitalscience-apex/functions.php on line 168 and I can’t get my site back even after deleting it.
Krzysiek Dróżdż says
Well, I wouldn’t use current_user_can for that… Codex says, that you can use it for role checking, but in the code you can find:
* While checking against particular roles in place of a capability is supported
* in part, this practice is discouraged as it may produce unreliable results.
So… Much better and secure way to do this is:
$user = wp_get_current_user();
if ( ! in_array( ‘administrator’, (array) $user->roles ) ) {
…
}
Rajdeep dey says
This code not working on my website… Did any one have any other solutions for hiding admin bar.
Lyndal Sirit says
i used it and it crashed my site, trying desperately to fix it now, i took the code back out and updated but I am getting an Error: Parse error: syntax error, unexpected ‘3’ (T_LNUMBER) in /home/lyndalspirit/public_html/wp-content/themes/primer/functions.php on line 516
WPBeginner Support says
Hi Lyndal,
Some times when users copy code from websites like WPBeginner, they also copy the line numbers which they are not supposed to copy. When they paste this code in their functions.php file it causes an error.
You need to connect to your site using an FTP client. Locate your functions.php go to the code you added and remove it. Save your changes.
Admin
SG says
Even after deleting it, my site is coming back HELP!
Chris says
This worked fine for me as-is, i stripped out the line numbers and stuck it at the end of my theme functions.php – instant success. thanks so much.
WPBeginner Support says
Hey Chris,
Glad you found it useful. Don’t forget to join us on Twitter for more WordPress tips and tutorials.
Admin
Job says
The Code works like charm. Thanks.
eli says
if(!current_user_can(‘administrator’)) {
add_filter(‘show_admin_bar’, ‘__return_false’);
}
Gordon Cockburn says
How do I remove an individual ex member from access to members only area of website
WPBeginner Support says
Login to your WordPress admin area using an Administrator account. Click on the Users menu item from the admin sidebar. This will show you a list of users registered on your WordPress site. Locate the user you wish to remove. Click on the Delete link below the username of the person you want to remove.
Admin
Jguiss says
Didn’t worked for me…
It’s worked with that : add_filter(‘show_admin_bar’, ‘__return_false’);
JGUISS says
JGUISS
Didn’t worked for me…
It’s worked with that : add_filter(‘show_admin_bar’, ‘__return_false’);
how does the code look like with this added I’m not familiar enough with php to add it in
The Little Binger says
Hello!
Thank you so much for being such a great help! I installed this code on the function file but it does not seem to work. I loaded my page on a different browser but the Log In bar is still there. Why is that? I also read your article about adding codes to the PHP file.
I hope you could help me out on this. Thanks!!
Vic says
Hi! First of all, thanks for these codes, it’s very helpful, provided I considered myself not a first timer anymore who remember to add after the codes!![:P](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)
I locked myself at the first time trying to add the php coding in my functions.php file as well, thanks to the “expert” web developer who didn’t show the full set of codes for a function. And thanks to your “what to do when you are locked out of WordPress admin area” site, I found out why I was locked out in the first place! But it took me a downtime of 3 days to figure out how to use the FTP, which at the end failed to function, but my webhost Helpdesk suggested me to use the File Manager in their Control Panel instead! Luckily it works! Lessons learnt the hard way, but worth it..
Just a kind suggestion, since this site was supposed meant for “WPBeginner”, I think all of the WP users beginner would appreciate if full set of codes are provided, rather than every other person “shouting” in the comment section that “The codes didn’t work, and locked me out”, and then you have to advise them to read a full length of another tutorial how to unlock their website, even though yes, you wish to teach us “How to fish” instead of “Fish for us” every time!
Anyway, thanks again and appreciate your efforts here in guiding us, the WP Beginners!
WPBeginner Support says
Thanks for the feedback. We try to make code easy to paste and use. However, usually there is already code in your functions.php file, which may affect the end result. We are glad you found your way out.
Admin
Louis says
It works just perfect!
Easy and functional.
Thank u!
lucas says
Yo your code line has ruined both of my sites I cannot acces the wp-admin at all I get a fatal error message.. how can I fix this please
WPBeginner Support says
You need to remove the code you added. See our guide on what to do when locked out of WordPress admin area.
Admin
Peters A P says
I did what was mentioned on the link you send me.
Now the entire site is gone
I cannot see anything, please check for yourself and see.
WPBeginner Support says
Please see our guide what to do when you are locked out of WordPress admin area
Admin
lucas says
Hi, did you manage to fix the problem? I had the exact same issue