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 (1)

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

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