Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Last active April 12, 2021 20:28
Show Gist options
  • Save kimcoleman/0528234f20dcd338933daed66a6c0a58 to your computer and use it in GitHub Desktop.
Save kimcoleman/0528234f20dcd338933daed66a6c0a58 to your computer and use it in GitHub Desktop.
Add the member's level ID to the <body> tag's "class" attribute.
<?php
/**
* Add the member's level ID to the <body> tag's "class" attribute.
*
* 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.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
*/
function add_pmpro_level_id_to_body_class( $classes ) {
global $current_user;
if( function_exists( 'pmpro_hasMembershipLevel' ) && pmpro_hasMembershipLevel() ) {
$classes[] = 'pmpro-body-has-level-' . $current_user->membership_level->ID;
}
return $classes;
}
add_filter( 'body_class', 'add_pmpro_level_id_to_body_class' );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Add the Member’s level ID to the body class for level-specific CSS styles." at Paid Memberships Pro here: https://www.paidmembershipspro.com/add-the-members-level-id-to-the-body-class-for-level-specific-css-styles/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment