Celebrate WordCamp Asia! - 30% OFF with coupon WC30 at checkout - Terms

Redirect Users to the Referring Page After LoginPRO

This knowledge base article relates to the WS Form User Management add-on. Included with the Agency edition or buy separately for other editions.

The WS Form User Management add-on can be used to create a login form for WordPress. Sometimes it can be helpful to redirect the user back to the referring page after a successful login. This tutorial explains how to modify the included Login form template so that it redirects to the referring page after a user logs in.

Enabling Referrer Tracking

The #tracking_referrer variable returns the URL of the page user visited before arriving at the current page. It can be placed in the URL setting of the Redirect action on the login page to return the user back to where they were after logging in.

WS Form disables all tracking by default to prioritize user privacy, therefore we first need to enable Referrer tracking. To do this:

  1. Click the Form Settings icon at the top of the layout editor.
  2. Click on the Tracking tab.
  3. Check the Referrer settings.
  4. Click Save & Close.

Configuring The Redirect Action

Now that we have referrer tracking enable, we can now use the #tracking_referrer as the URL to redirect to after logging in. To do this:

  1. Click the Actions icon at the top of the layout editor.
  2. Click the Settings  icon next to the Redirect action.
  3. In the URL setting add: #tracking_referrer
  4. Click Save & Close.

Setting a Fallback URL for Redirects

In some case you may want to redirect to an alternative URL instead of the referring page. For example, you wouldn’t want to redirect back to a reset password page. Instead you may wish to redirect to a My Account page or perhaps the home page.

This is possible using the Fallback URL feature of the Redirect action.

In this example, we’ll create a fallback URL of /my-account/ if the referring page path is /reset-password/.

  1. Click the Actions icon at the top of the layout editor.
  2. Click the Settings  icon next to the Redirect action.
  3. Check the Enable Fallback URL setting.
  4. Click the Add icon by the Fallback URL Conditions setting to add a new condition.
  5. In the If URL column, choose Contains.
  6. In the Value column, we enter the string we’ll check for in the URL, for example: reset-password
  7. Repeat this for any other paths you want to include in the condition.
  8. Enter the Fallback URL, for example: /my-account/
  9. Click Save & Close.

A full example is shown below:

WS Form - Actions - Redirect - Tracking Referrer

WS Form will now redirect users to the Fallback URL if the referring page matches specific conditions. This prevents users from being sent back to pages like a password reset screen and instead directs them to a more appropriate destination, such as a My Account or your home page.