Redirecting Logged-In Users from WPForms Login Pages

Want to redirect users who are already logged in when they visit your login form? While WPForms allows you to hide the login form or display a message for logged-in users through the User Registration settings, this guide will show you how to automatically redirect them to a specific page using PHP code.

For information about the built-in logged-in user options, please review our User Registration documentation.

Setting Up Your Form

To begin, you’ll need to create a login form and add it to a WordPress page.

If you need any assistance in how to create a login form with the WPForms User Registration addon, please check out this documentation.

Adding the Redirect Code

Add this code snippet to your site to enable automatic redirection. If you need help adding custom code, please review our guide on adding code snippets.

If you’re not sure how or where to add snippets to your site, please take a look at this tutorial.

You’ll need to customize two values in this code:

  1. Line 10: Replace 345 with the ID of the page containing your login form. To find your page ID, edit the page and look for the number after ?post= in the URL.
  2. Line 16: Replace http://www.example-site.com/your-page/ with the URL where you want to redirect logged-in users.
look for the number in the URL when editing the page to find the page ID number

And that’s it! Would you like to have your form redirected to a new browser window? Check out our tutorial on How to Open Redirect in a New Window.

Reference Action

template_redirect