Last active
April 12, 2021 20:28
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/