The code example below will allow you to add the logged-in member’s level ID (if available) to your site’s body class. This can prove useful if you want to change the style of or even hide elements based on level.

Default Body and Post Classes

WordPress offers several functions that can filtered by plugins to add classes to your site’s body element and posts elements. Below are the default filters Paid Memberships Pro adds to these elements:

Classes already added using the body_class Function

Membership Requirement-related
  • pmpro-body-level-required
    Added if the post requires membership.
  • pmpro-body-has-access
    Added if the logged in user has access to the members-only content.
  • pmpro-body-level-$levelID
    Added for each membership level the post requires.

Plugin Page-related
These classes will be added based on the plugin page settings.
  • pmpro-account
  • pmpro-billing
  • pmpro-cancel
  • pmpro-checkout
  • pmpro-invoice
  • pmpro-levels

The Code Recipe

This code recipe requires a Plus Account or higher.

View Membership Options

Comments (3)

If you are adding this to a customization plugin you should not have to add an additional PHP closing tag.

Could this be extended so that logged in commenters have a level name or similar on their comments? For example, I’m commenting here. After the comment is approved, it should show on this page. Maybe it pulls in my name and gravatar. Would be cool (and useful to me on my site) to prioritize my paid user’s comments. Could provide ancillary social proof to other site visitors, too.

Leave a Reply

For faster support related to issues on your specific site please open a ticket in our members support area.

Your email address will not be published. Required fields are marked *