Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Puchar WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Jak wyłączyć pasek administratora WordPress dla wszystkich użytkowników z wyjątkiem administratorów?

Uwaga redakcyjna: Otrzymujemy prowizję z linków partnerskich na WPBeginner. Prowizje nie mają wpływu na opinie i oceny naszych redaktorów. Dowiedz się więcej o Proces redakcyjny.

Czy chcesz wyłączyć pasek administratora WordPress dla wszystkich użytkowników z wyjątkiem administratorów?

Domyślnie można łatwo wyłączyć pasek administratora WordPress dla poszczególnych użytkowników. Może to jednak zająć trochę czasu, jeśli masz wielu zarejestrowanych użytkowników na twojej witrynie.

W tym artykule pokażemy, jak łatwo wyłączyć pasek administratora WordPress dla wszystkich użytkowników z wyjątkiem administratorów.

How to disable WordPress Admin Bar for All Users except administrators

Czym jest pasek administratora WordPress?

Domyślnie WordPress wyświetla pasek administratora u góry ekranu dla wszystkich zalogowanych użytkowników. Gdy jesteś zalogowany na swoje konto, możesz zobaczyć ten pasek narzędzi w obszarze administracyjnym WordPress i na wszystkich innych stronach.

The WordPress admin bar

Pasek narzędzi administracyjnych WordPress zawiera przydatne skróty do różnych obszarów zaplecza WordPress, a skróty te zmieniają się w zależności od roli i uprawnień użytkownika w WordPress.

Jednak pasek administratora może rozpraszać uwagę, gdy patrzysz na front-end twojej witryny internetowej.

Może to również mieć wpływ na wygląd twojej witryny internetowej i wrażenia użytkownika. Może to stanowić problem, jeśli budujesz lub zarządzasz witryną WordPress dla strony trzeciej, ponieważ uniemożliwia im to zobaczenie, jak naprawdę wygląda ich witryna.

Na szczęście istnieje wiele sposobów na wyłączenie paska administratora dla wszystkich użytkowników z wyjątkiem administratorów. Wystarczy skorzystać z poniższych odnośników, aby przejść do wybranej metody:

Film instruktażowy

Subscribe to WPBeginner

Jeśli wolisz pisemne instrukcje, czytaj dalej.

Metoda 1: Wyłącz pasek administratora WordPress dla poszczególnych użytkowników

Możesz wyłączyć pasek administratora dla określonych użytkowników, po prostu edytując ich profil użytkownika. Jest to szybka i łatwa metoda, jeśli chcesz usuwać pasek tylko dla niewielkiej liczby osób. Jeśli jednak prowadzisz witrynę członkowską z dużą liczbą użytkowników, zalecamy wybranie innej metody.

Aby ręcznie usuwać pasek administratora, wystarczy przejść do strony Użytkownicy ” Wszyscy użytkownicy w kokpicie administratora WordPress. Następnie najedź kursorem myszy na użytkownika, który nie potrzebuje paska administratora i kliknij „Edytuj”, gdy się pojawi.

How to edit a user's profile in WordPress

Spowoduje to otwarcie profilu tego użytkownika.

W tym miejscu należy odznaczyć pole obok opcji „Pokaż pasek narzędzi, gdy zobaczysz witrynę”.

How to hide the admin toolbar for non-admin users

Następnie przewiń ekran do dołu i kliknij przycisk „Aktualizuj użytkownika”, aby zapisać twoje zmiany. Spowoduje to wyłączenie paska administratora tylko dla tej konkretnej osoby.

Aby ukryć pasek narzędzi dla większej liczby użytkowników, wystarczy wykonać tę samą procedurę opisaną powyżej.

Metoda 2: Wyłącz pasek administratora dla wszystkich użytkowników z wyjątkiem administratorów (zalecane)

Jeśli chcesz ukryć pasek administratora dla wielu różnych osób, ręczna zmiana ustawień każdego użytkownika zajmie dużo czasu i wysiłku.

Z tego powodu zalecamy wyłączenie paska administratora poprzez dodanie kodu do pliku functions.php, który jest plikiem motywu WordPress. Jeśli nie robiłeś tego wcześniej, zapoznaj się z naszym przewodnikiem na temat kopiowania i wklejania fragmentów kodu w WordPress.

Niektóre przewodniki zalecają ręczną edycję plików motywu, ale może to powodować typowe błędy WordPressa, a nawet całkowicie zepsuć twoją witrynę internetową.

Z tego powodu zalecamy korzystanie z WPCode. Jest to najlepsza wtyczka do fragmentów kodu, która ułatwia dodawanie własnego kodu w WordPressie bez narażania twojej witryny na ryzyko.

Najpierw należy zainstalować i włączyć darmową wtyczkę WPCode. Więcej informacji można znaleźć w naszym przewodniku krok po kroku na temat instalacji wtyczki WordPress.

Po włączaniu wtyczki, przejdź do Code Snippets ” Add Snippet.

Hiding the admin toolbar using WPCode

Tutaj zobaczysz wszystkie gotowe fragmenty kodu, które możesz dodać do swojej witryny. Obejmuje to fragment kodu, który pozwala całkowicie wyłączyć komentarze, przesyłać rodzaje plików, których WordPress zwykle nie pomaga technicznie, wyłączyć strony załączników i wiele więcej.

Na następnym ekranie musisz najechać kursorem myszy na opcję „Add Your Custom Code (New Snippet)” i kliknąć przycisk „Use snippet”, gdy się pojawi.

Adding custom code to your WordPress website with WPCode

Na następnym ekranie wpisz tytuł fragmentu kodu. To jest tylko dla twojego odniesienia, więc możesz użyć czegokolwiek chcesz.

Następnie otwórz listę rozwijaną „Rodzaj kodu” i wybierz „Fragment kodu PHP”.

Adding a PHP snippet to WordPress using WPCode

Po wykonaniu tej czynności wystarczy wkleić następujący kod do edytora:

add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}

Ten kod identyfikuje wszystkich użytkowników niebędących administratorami, którzy nie patrzą na obecny, aktualny kokpit administratora. Dla tych użytkowników wyłącza pasek administratora WordPress.

Następnie przewiń stronę w dół do sekcji „Wstaw”. Tutaj możesz zachować domyślną metodę” Auto wstawić”, aby upewnić się, że kod działa wszędzie.

Automatically inserting code into a WordPress website

Na koniec przewiń ekran do góry i kliknij suwak „Nieaktywne”, aby wyświetlić „Aktywne”.

Następnie wystarczy kliknąć przycisk „Zapisz fragment kodu” lub „Aktualizuj”, aby fragment kodu stał się aktywny.

Publishing a custom code snippet to WordPress

To wszystko! Pamiętaj tylko, aby sprawdzić swoją witrynę internetową WordPress, aby upewnić się, że wszystko działa poprawnie.

Metoda 3: Wyłącz pasek administratora WordPress dla wszystkich użytkowników z wyjątkiem administratorów (kod nie jest wymagany)

Jeśli nie chcesz dodawać kodu do twojej witryny internetowej, możesz ukryć pasek administratora za pomocą wtyczki. Hide Admin Bar Based on User Roles pozwala usuwać pasek administratora na podstawie różnych ról użytkowników, więc jest to dobry wybór, jeśli chcesz wyłączyć pasek dla wszystkich członków, klientów WooCommerce lub innej roli użytkownika.

Najpierw należy zainstalować i włączyć wtyczkę Hide Admin Bar Based on User Roles. Aby uzyskać więcej informacji, zobacz nasz przewodnik krok po kroku, jak zainstalować wtyczkę WordPress.

Po włączaniu należy przejść do strony Ustawienia ” Ukryj pasek administratora. W tym miejscu zaznacz pola obok ról użytkowników, dla których chcesz wyłączyć pasek administratora.

Hiding the admin toolbar for specific user roles

Po wykonaniu tej czynności wystarczy kliknąć przycisk „Zapisz zmiany”, aby zapisać twoje ustawienia.

Metoda 4: Wyłącz pasek administratora dla wszystkich użytkowników (w tym administratorów)

Czy chcesz wyłączyć pasek administratora dla wszystkich użytkowników, w tym administratorów witryny?

Możesz to zrobić, dodając kod, który wyłącza pasek administratora dla wszystkich, którzy zobaczą publiczne strony twojej witryny. Oznacza to, że pasek administratora pojawi się tylko wtedy, gdy jesteś w obszarze administracyjnym WordPress.

Aby uprościć sprawę, WPCode ma dokładnie ten fragment kodu, którego potrzebujesz we wbudowanej bibliotece fragmentów kodu. Wystarczy przejść do zakładki Fragmenty kodu Biblioteka.

The WPCode code snippet plugin for WordPress

Tutaj należy wyszukać „Disable The WP Admin Bar”.

Gdy pojawi się odpowiedni fragment kodu, wystarczy kliknąć przycisk „Użyj fragmentu kodu”.

The ready-made Disable The WP Admin Bar code snippet

Wtyczka automatycznie doda kod do twojej witryny, nada mu opisowy tytuł, wybierze odpowiednią metodę wstawienia, a nawet doda tagi, które pomogą ci zidentyfikować fragment kodu.

Oto jak wygląda kod:

/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );

Teraz wystarczy przełączyć przełącznik z „Nieaktywny” na „Aktywny”, a następnie kliknąć „Aktualizuj”.

Adding custom code to WordPress

Teraz, jeśli przejdziesz na front witryny internetowej, będąc zalogowanym na swoje konto WordPress, pasek administratora zniknie.

Mamy nadzieję, że ten artykuł pomógł ci dowiedzieć się, jak wyłączyć pasek administratora WordPress dla wszystkich użytkowników z wyjątkiem administratorów. Warto również zapoznać się z naszym przewodnikiem po zabezpieczeniach WordPress i naszym porównaniem najlepszych kreatorów stron WordPress do tworzenia własnych układów stron bez żadnego kodu.

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.

Ujawnienie: Nasze treści są wspierane przez czytelników. Oznacza to, że jeśli klikniesz na niektóre z naszych linków, możemy otrzymać prowizję. Zobacz jak WPBeginner jest finansowany, dlaczego to ma znaczenie i jak możesz nas wspierać. Oto nasz proces redakcyjny.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Najlepszy zestaw narzędzi WordPress

Uzyskaj BEZPŁATNY dostęp do naszego zestawu narzędzi - zbiór produktów i zasobów związanych z WordPressem, które każdy profesjonalista powinien mieć!

Reader Interactions

166 komentarzyZostaw odpowiedź

  1. 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!

  2. Hajjalah says

    I have a Question and Answer plugin on my blog which automatically adds admin bar for all users whenever i make an update on it. I am glad that WPCode has completely disabled this annoying feature. Thanks WPBeginner for the helpful article.

  3. Moinuddin Waheed says

    This is very needed to hide the admin bar to all the user’s except the administrator.
    I have thought of doing this multiple times over specially when I was running news website and I had many authors and contributors.
    Showing them admin bar is not only unnecessary but annoying too.
    Really appreciate for the steps to get rid of this admin bar and keep it for only the administrator.

  4. Amos Showole says

    Wow… This is great, you solved an issue I faced with on one of my WordPress website that BuddyPress was installed on….

  5. 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’);

  6. 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.

      Administrator

  7. 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

      If method 3 is not working for you, we would recommend trying one of the other methods to test.

      Administrator

    • WPBeginner Support says

      You may want to try clearing your cache for the most common reason for the change not being visible.

      Administrator

  8. 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.

      Administrator

  9. 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.

  10. 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

      Administrator

  11. 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?

  12. Jim says

    Can this code be altered to allow the WordPress Admin bar for Admins AND moderators, but hide it for everyone else?

    Thanks!

  13. 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.

  14. 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.

  15. 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.

      Administrator

  16. 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 :)

    • 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

  17. 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.

  18. 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

  19. 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

  20. 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.

  21. 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.

  22. 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 ) ) {

    }

  23. 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.

      Administrator

  24. 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

      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.

      Administrator

    • 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

  25. 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!!

Zostaw odpowiedź

Dziękujemy za pozostawienie komentarza. Pamiętaj, że wszystkie komentarze są moderowane zgodnie z naszymi polityka komentarzy, a Twój adres e-mail NIE zostanie opublikowany. NIE używaj słów kluczowych w polu nazwy. Przeprowadźmy osobistą i konstruktywną rozmowę.