Paid Memberships Pro’s built-in setting for hiding the WordPress Toolbar only covers members with the Subscriber role. If your site uses custom roles, whether through the Roles for Membership Levels Add On or your own code, those members still see the full admin toolbar when they are logged in on the front end.

This code recipe uses the pmpro_hide_toolbar filter to extend that same toolbar-hiding behavior to any custom roles you specify.

Hide the WordPress Toolbar for Additional User Roles

Do You Need This Recipe?

This recipe is a good fit if:

  • Your site assigns members custom user roles, through the Roles for Membership Levels Add On or your own code.
  • Members with those custom roles can still see the WordPress Toolbar when they are logged in on the front end.
  • You want the same toolbar-hiding behavior Paid Memberships Pro already provides for the Subscriber role.

If every member on your site uses the built-in Subscriber role, you do not need this recipe. Turn on PMPro’s built-in setting instead, under Memberships > Settings > Advanced.

About the Code Recipe

The pmpro_hide_toolbar filter receives a boolean, $hide, and PMPro checks that value to decide whether to remove the toolbar for the current user. PMPro’s built-in setting already returns true for the Subscriber role. This recipe hooks into the same filter and checks the logged-in user’s roles against a list you define with array_intersect(). If there is a match, it sets $hide to true, and the toolbar is hidden for that member too, the same as it would be for a Subscriber.

Because the check runs on $current_user->roles, it works for any role, whether it is one WordPress ships with (such as editor) or a custom role your site created, including roles added by the Roles for Membership Levels Add On.

Note: This filter is independent of the “Hide the Toolbar from all users with the Subscriber role” checkbox under Memberships > Settings > Advanced. The snippet hides the toolbar for your custom roles regardless of whether that checkbox is turned on. It is also independent of the “Block all users with the Subscriber role from accessing the Dashboard” checkbox in the same section, which uses its own separate filter, pmpro_block_dashboard. Hiding the toolbar for a custom role does not block that role from accessing the WordPress Dashboard.

PMPro Advanced Settings page showing the Restrict Dashboard Access checkboxes for blocking Dashboard access and hiding the Toolbar for the Subscriber role

The Code Recipe

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

How To Customize This Code Recipe

  • Add your custom roles (line 20): Update the $roles_to_hide array with the role slugs you want to hide the toolbar for. Role slugs are case-sensitive and must match exactly, such as editor for WordPress’s built-in Editor role, or a custom role slug created by the Roles for Membership Levels Add On.



Was this article helpful?
YesNo

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics