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

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

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

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

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

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

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

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

  8. 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);
    }
    }

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

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

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

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

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

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

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

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

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

  18. niki says

    Fantastic! Except I also have the blank space visible where the admin bar would be. Does anyone have a fix for this?

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

  20. 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? ;-)

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

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

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

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

  25. glueckpress says

    Nice. For Superadmins in a Multisite install it would read like if(!current_user_can(’manage_network’)) //etc.

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