Skip to content

Instantly share code, notes, and snippets.

@kimwhite
Last active November 5, 2025 16:28
Show Gist options
  • Save kimwhite/ebdd629d607b385fa5dc55c3cade3945 to your computer and use it in GitHub Desktop.
Save kimwhite/ebdd629d607b385fa5dc55c3cade3945 to your computer and use it in GitHub Desktop.
Customizes the Paid Memberships Pro no access message for members and non-members.
<?php // do not copy this line.
/**
* This recipe changes the Restricted Content Message and button
* depending on whether the viewer is a member or not.
*
* 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 my_pmpro_custom_no_access_message_members_upgrade_nonmembers_join( $body, $level_ids ) {
global $pmpro_pages;
if ( pmpro_hasMembershipLevel() ) {
// Logged-in members who already have a membership level.
// You can change the message text below.
$body = '<p><strong>You must upgrade your membership to access this content.</strong></p>';
$body .= '<p>This content is available to higher-level members. You can review upgrade options here:</p>';
// You can change the button text ("Upgrade Now") or the link (currently goes to Levels page).
$body .= '<p><a href="' . esc_url( pmpro_url( 'levels' ) ) . '" class="pmpro_btn pmpro_btn-primary">Upgrade Now</a></p>';
} else {
// Guests or non-members (no active membership).
// You can change the message text below.
$body = '<p><strong>You must be a member to access this content.</strong></p>';
// !!levels!! dynamically inserts the list of levels required for access.
$body .= '<p>!!levels!!</p>';
// You can change the button text ("Join Now") or link (currently goes to Levels page).
$body .= '<p><a href="' . esc_url( pmpro_url( 'levels' ) ) . '" class="pmpro_btn pmpro_btn-primary">Join Now</a></p>';
}
return $body;
}
add_filter( 'pmpro_no_access_message_body', 'my_pmpro_custom_no_access_message_members_upgrade_nonmembers_join', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment