When members log out of your site, the experience should feel intentional. By default, WordPress redirects users to the standard login page, rarely the right destination for a membership site. You may want members to land on a custom “see you soon” page, a re-engagement offer, or a page specific to their membership level.

These code recipes use the WordPress wp_logout action to redirect users to a custom destination after logout. Choose a single destination for everyone, or send users to different pages depending on their membership level.

Code recipe thumbnail showing the PMPro login page with a green confirmation badge indicating the user was logged out and redirected

Do You Need This Recipe?

This recipe is a good fit if:

  • You want to send members to a specific page after logout rather than the default WordPress login screen
  • You want to show different post-logout pages to members of different levels (for example, sending Gold members to a retention offer and non-members elsewhere)
  • Your PMPro login page is branded and you want members to land there after logout so they can log back in easily

If the default WordPress logout behavior is acceptable for your site, no recipe is needed.

Screenshot showing the PMPro login page with a green confirmation badge indicating the user was logged out and redirected

Understanding the wp_logout Hook

These recipes are triggered by the wp_logout WordPress hook, which fires automatically whenever a user logs out of your site. You can use it to run custom PHP code, most commonly to redirect users to a specific page or display a custom message after logout.

About The Code Recipes

These two recipes cover the two most common use cases and work independently. Use one or the other depending on your needs.

  • Recipe 1 redirects users based on their membership level at the moment of logout. Members with a specific level go to one page; everyone else goes to another.
  • Recipe 2 sends all users to the same destination after logout, regardless of membership status. Useful when you want a single branded logout landing page for everyone.

Recipe 1: Redirect Based on Membership Level

To customize this recipe:

  • Change the membership level ID 1 on line 21 to your preferred membership level ID.
  • Replace /level-1 on line 22 with the slug of the page to redirect members of that level to after logout.
  • Replace /other-levels on line 26 with the slug of the page for non-members and members on other levels.
  • To handle additional levels, chain elseif ( pmpro_hasMembershipLevel( X, $user_id ) ) blocks before the final else, each with its own redirect destination.

Recipe 2: Redirect All Users to the Same Page

To customize this recipe:

  • Replace home_url() on line 18 with home_url( 'your-page-slug' ) to redirect to a specific page. For example, home_url( 'login' ) sends users to a page with the slug /login.
  • To always redirect to your configured PMPro login page regardless of its slug, use pmpro_url( 'login' ) instead of home_url().

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