Improve the user experience by redirecting members back to the protected content they just viewed. The steps below will show you how to set the referring URL in the messages displayed on protected posts or pages.
When a user clicks “Log In” on a piece of members-only content, they will be redirected back to that URL after successful login.
Login Redirection Overview
Core WordPress login redirection is based on the user’s role. Paid Memberships Pro redirects all users, regardless of their role, to the Membership Account page.
You can read this documentation on redirect logic in PMPro to better understand the default redirects in the plugin.
Using the !!referrer!! attribute
The default “Message for Logged-out Users” (under Memberships > Settings > Advanced Settings) provides a link to “Log In” and a link to “Join Now”.
Update the “Log In” link to the following:
<a href="!!login_page_url!!?redirect_to=!!referrer!!">Log In</a>
This will redirect your member to the last piece of protected content they tried to view.
Redirect Login by Membership Level
This article demonstrates how to set up redirection back to the referring page. We have another article that demonstrates how to redirect members on login based on their membership level. This method can work in conjunction with the example in this guide and will only redirect the member if no referrer is passed to the login page URL.