Skip to content

Instantly share code, notes, and snippets.

@dwanjuki
Created December 18, 2025 13:35
Show Gist options
  • Select an option

  • Save dwanjuki/cc0b9a1abdfdcc0ee62cfba37bd57eab to your computer and use it in GitHub Desktop.

Select an option

Save dwanjuki/cc0b9a1abdfdcc0ee62cfba37bd57eab to your computer and use it in GitHub Desktop.
<?php
/**
* Redirect to the PMPro Login page after logout.
*
* 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 wp_redirect_to_pmpro_login_after_logout() {
global $pmpro_pages;
// Bail if PMPro is inactive or PMPro login page isn't set.
if ( empty( $pmpro_pages ) || empty( $pmpro_pages['login'] ) ) {
return;
}
// Get login page URL.
$pmpro_login_url = get_permalink( $pmpro_pages['login'] );
// Redirect.
wp_safe_redirect( $pmpro_login_url );
exit;
}
add_action( 'wp_logout', 'wp_redirect_to_pmpro_login_after_logout' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment