The WishList Member standard functionality will redirect a member to the set After Login page any time they login. This is useful when you want to display a Member Dashboard to your members each time right after they login. But, what if you want to return a user to the same piece of protected content they were trying to access before logging in?
So instead of viewing a member dashboard in this case, they will be sent back to the specific piece of content they were trying to access.
There is an option in WishList member you can use that will adjust the typical after login functionality in order to direct a member back to the original content they were trying to access.
You can make this happen by using the the WishList Member Login Form on the set Non-Members page. Lets get into the details below.
Using the Login Form on the Non-Members Page
The Non-Members page can be set in the Advanced Options > Global Defaults > Error Pages section of WishList Member.
If a member clicks on a protected link or tries to access any protected content and if they are not logged in, they are automatically redirected to the set Non-Members page.
The member is able to login and will then be directed to the protected content they were trying to access. This will all happen if the WishList Member Login Form mergecode is being used to display a login form on that Non-Members page.
Note: If the Message option is selected for the Non-Members page, it has the Login Form mergecode inserted by default.
Login Form mergecode: [wlm_loginform]
The key point being the WishList Member Login Form mergecode needs to be inserted into the Non-Members page in order to redirect the member back to the content they were originally trying to access. A member using that login form to login to the site is what will redirect them back to the original piece of protected content they were trying to access.
Below is a screenshot displaying the login form in the message that will appear to the member when they try to access protected content while not logged in to the site. This example is using the default Message as the After Login page.
Inserting the Login Form on the Non-Members Page
You also have the ability to insert the Login Form mergecode into any page or post which will insert the login form.
Login Form Mergecode: [wlm_loginform]
Adding that mergecode to the content section of a page or post will insert a login form.
There is also a Mergecode and Shortcode insert option that appears on Pages and Posts when using the WordPress Gutenberg editor.
This blue icon appears on the Classic Block of the Gutenberg editor and is a quick way to add mergecodes and shortcodes to a page or post. (The WishList Member Shortcode Creator can also be used at any time to create merges or shortscodes).
So you can insert the Login Form mergecode into any page and set that as the After Login page if you would like. This will allow members (who are not logged in) that click on a protected link to be sent to the Non-Members page where they can then login (using the login form generated by the Login Form mergecode placed on the Non-Members page) and they will then be redirected to the content they were trying to access.
This will work when setting either a Message or Page as the After Login option (as long as they use the Login Form mergecode).
Please keep in mind that this Login Form mergecode must be included on the Non-Members page and members must login using that login form in order for the redirect to work as expected. If not, they would be redirected to the set After Login page.
Using the Login Form mergecode on the Non-Members page allows members who are not yet logged in to be redirected back to the content they were trying to access once they do login.