### [Redirecting Logged-In Users from WPForms Login Pages](https://wpforms.com/developers/how-to-automatically-redirect-if-user-is-already-logged-in/)

**Published:** February 24, 2022
**Author:** Umair Majeed

**Excerpt:** This tutorial will walk you through how to automatically redirect a user away from a login form if they are already logged in using PHP. 

**Content:**

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](https://wpforms.com/docs/how-to-install-and-use-user-registration-addon-with-wpforms/#settings).

## 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](https://wpforms.com/how-to-display-wordpress-login-and-register-forms-on-any-page/ "How to Create Login and Registration Forms on Any WordPress Page").

## 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](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/ "How to Add Custom PHP or JavaScript for WPForms").

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](https://wpforms.com/wp-content/uploads/2022/02/wpforms-find-page-id.jpg)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](https://wpforms.com/developers/how-to-open-redirect-in-a-new-window/ "How to Open Redirect in a New Window").

## Reference Action

[template\_redirect](https://developer.wordpress.org/reference/hooks/template_redirect/ "Using WordPress template_redirect action")

**Categories:** Addons

**Tags:** PHP

---

