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.

Banner for Advanced Code Recipe Tutorial for Paid Memberships Pro

Default Body and Post Classes

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

Membership Requirement Classes Added to the <body> Tag

  • pmpro-body-level-required: Added if the post requires membership.
  • pmpro-body-has-access: Added if the logged in user has access to the content (public or members-only). Also added to all content that is not restricted at all (public).
  • pmpro-body-level-$levelID: Added for each membership level the post requires.
  • pmpro-account
  • pmpro-billing
  • pmpro-cancel
  • pmpro-checkout
  • pmpro-invoice
  • pmpro-levels

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.

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
Was this article helpful?
YesNo