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

WordPressの管理バーを管理者以外のすべてのユーザーで無効化する方法

一部の読者から、WordPressの管理バーを無効化する方法を尋ねられました。これは小さな調整ですが、ユーザーによっては、よりすっきりとしたユーザーインターフェースを維持したい、管理者以外のユーザーのユーザー体験を向上させたいなど、さまざまな理由でこれを行うことを好みます。

初期設定では、個々のユーザーのWordPress管理バーを簡単に無効化することができます。しかし、サイトに多数の登録ユーザーがいる場合、これは時間のかかる作業です。

この投稿では、WordPressの管理バーを管理者以外のすべてのユーザーに対して簡単に無効化する方法を紹介します。

How to disable WordPress Admin Bar for All Users except administrators

WordPressの管理バーとは?

初期設定では、WordPressはログイン中のすべてのユーザーの画面上部に管理バーを表示します。アカウントにログインすると、WordPressの管理エリアやその他のすべてのページでこのツールバーが表示されます。

The WordPress admin bar

WordPressの管理ツールバーには、WordPressのさまざまなバックエンドエリアへの便利なショートカットがあり、これらのショートカットは、ユーザーのWordPressにおける権限とグループによって変わります。

しかし、サイトのフロントエンドを見ていると、管理バーが邪魔になることがある。

また、サイトのデザインやユーザーエクスペリエンスにも影響を与える可能性があります。これは、第三者のためにWordPressサイトを構築または管理している場合に問題となる可能性があります。

幸いなことに、管理者以外のすべてのユーザーに対して管理バーを無効化する方法は複数あります。以下のクイックリンクから、使いたい方法にジャンプしてください:

動画チュートリアル

Subscribe to WPBeginner

文章での説明がお好きな方は、そのまま読み進めてください。

方法1:WordPressで各ユーザーの権限を変更する

ユーザープロフィールを編集するだけで、特定のユーザーの管理バーを無効化することができます。これは、少数のユーザーに対して管理バーを削除する必要がある場合、迅速で簡単な方法です。しかし、多くのユーザーを抱える会員制サイトを運営している場合は、別の方法を選択することをお勧めします。

管理バーを手動で削除するには、WordPress管理ダッシュボードのユーザー ” すべてのユーザーページに移動するだけです。そして、管理バーが不要なWordPressユーザーにマウスオーバーし、表示されたら「編集」をクリックします。

How to edit a user's profile in WordPress

そのユーザーのプロフィールが表示されます。

ここから、「サイト表示時にツールバーを表示する」オプションの隣のチェックボックスを外す。

How to hide the admin toolbar for non-admin users

その後、画面を一番下までスクロールし、「ユーザーを更新」をクリックして変更を保存します。これで、その特定のユーザーのみ管理バーが無効化されます。

より多くのユーザーのツールバーを非表示にするには、上記と同じ手順を踏むだけです。

方法2:コードを使用して非管理ユーザーの管理バーを無効化する(推奨)

管理バーを多くのユーザーに対して非表示にする必要がある場合、各ユーザーの設定を手動で変更するのは大変な時間と労力がかかります。

そのため、WordPressのテーマファイルであるfunctions.phpファイルにコードを追加して管理バーを無効化することをお勧めします。

テーマファイルを手動で編集するように指示するガイドもありますが、WordPressの一般的なエラーを引き起こし、サイトを完全に壊してしまう可能性もあります。

そのため、WPCodeの使用をお勧めします。これは最高のコードスニペットプラグインで、サイトを危険にさらすことなくWordPressにカスタムコードを簡単に追加することができます。

WPCodeを使って、管理画面の配色を変更したり、「Howdy Admin」テキストを削除したり、表示オプションボタンを無効化したりしました。

まず、無料のWPCodeプラグインをインストールし、有効化する必要があります。 詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

プラグインを有効化したら、Code Snippets ” Add Snippetに進みます。

Hiding the admin toolbar using WPCode

ここでは、あなたのサイトに追加できるすべての既製のスニペットが表示されます。

実際、WPCodeには、管理バーを無効化するのに必要なコード・スニペットが、ビルトインのスニペット・ライブラリに用意されています。コードスニペットライブラリにアクセスしてください。

The WPCode code snippet plugin for WordPress

ここで、「Disable The WP Admin Bar」を検索する。

適切なスニペットが表示されたら、その「スニペットを使う」ボタンをクリックするだけだ。

The ready-made Disable The WP Admin Bar code snippet

プラグインは自動的にサイトにコードを追加し、コードに説明的なタイトルを付け、正しい挿入方法を選択し、さらにスニペットを識別するためのタグを追加します。

コードはこんな感じだ:

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

すべてのユーザーに対して管理バーを無効化することが目的であれば、スイッチを「無効化」から「有効化」に切り替え、「更新」をクリックするだけです。

Adding custom code to WordPress

しかし、我々の目的は非管理ユーザーに対してWordPressの管理バーを無効化することなので、コードを少し調整する必要がある。

既存のコードを以下のように置き換えることができる:

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

function restrict_admin_bar( $show ) {
    return current_user_can( 'administrator' ) ? true : false;
}

このコードは、現在管理ダッシュボードを見ていない非管理ユーザーを識別します。これらのユーザーに対しては、WordPress 管理バーを無効化します。

その後、ページを下にスクロールして「インサーター」セクションまで進む。ここでは、初期設定の’Auto Insert’メソッドのままにしておくと、どこでもコードが実行されるようになります。

Automatically inserting code into a WordPress website

最後に画面を一番上までスクロールし、「Inactive」スライダーをクリックして「Active」と表示させる。

その後、「スニペットを保存」または「更新」ボタンをクリックするだけで、コード・スニペットが有効になります。

Publishing a code snippet to disable the WordPress admin bar for non-admin users

以上で作業は終了です!WordPressサイトが正常に動作していることを確認するのを忘れないでください。

方法3:無料のプラグインを使って、非管理ユーザー用の管理バーを無効化する。

サイトにコードを追加したくない場合は、プラグインを使って管理バーを非表示にすることができます。Hide Admin Bar Based on User Rolesは異なるユーザー権限に基づいてツールバーを非表示にすることができるので、すべてのメンバーやWooCommerceの顧客、その他のユーザー権限で管理バーを無効化したい場合におすすめです。

まず、Hide Admin Bar Based on User Rolesプラグインをインストールして有効化する必要があります。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

有効化した後、Settings ” Hide Admin Bar Settingsページに移動する必要があります。ここで、管理バーを無効化したいユーザー権限グループの横にあるボックスにチェックを入れます。

Hiding the admin toolbar for specific user roles

あとは「変更を保存」をクリックするだけで、設定が保存されます。

WordPressの管理バーを管理者以外のすべてのユーザーに対して無効化する方法について、この投稿がお役に立てれば幸いです。また、WordPress で投稿の変更をメールで通知する方法や、WordPress の活動ログとトラッキングプラグインのエキスパートによるベストセレクションもご覧ください。

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

163件のコメントLeave a Reply

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

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

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

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

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

    • For what you are wanting, you would want to remove: && !is_editor()

      Then it should work how you are wanting.

      Admin

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

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

      Admin

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

      Admin

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

    • 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

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

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

    • 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

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

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

    Thanks!

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

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

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

    • 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

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

    • 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

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

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

    • Thanks for this updated code, Alex. Simple and works great.

      Put it in child theme functions.php and forget about it. :)

    • 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’);
      }
      }

    • 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

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

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

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

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

    }

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

    • 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

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

    • 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

      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

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

  25. 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!
    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.. :P
    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! :)

    • 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

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.