Automatic logged-in Page Redirect
A Wordpress plugin for automatic Page Redirection for logged in users
by Patrick Stecker · github.com/patrickstecker/automatic-page-redirect · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/patrickstecker/automatic-page-redirect/archive/refs/heads/main.zipThe Automatic logged-in Page Redirect plugin is a WordPress plugin that redirects logged-in users to a custom page when they try to access a page. In the same way, you can configure that users that are not logged in are getting redirected somewhere else. It works in combination with the Advanced Custom Fields (ACF) plugin. If you set the ACF Field "Redirect to Page if Logged in" (redirect_to_page_if_logged_in) and another field "Redirect to Page if NOT Logged in" (redirect_to_page_if_not_logged_in), then it will automatically redirect you from there if it is set.
Additionally you can specify redirects in the url. If you set a query parameter "redirect_logged_in", the user will be redirected to the value of this parameter if he/she is logged in. By specifying the query parameter "redirect_logged_out", a user that is not logged in gets redirected.
If both the ACF and the query param is set, the query param has more priority and the user will be redirected to the url specified by the query param.
Installation
Install and activate the Advanced Custom Fields plugin.
- Download the newest Realease from this repository as a ZIP
- In your WordPress Admin Dashboard, go to
Plugins > Add New > Upload Plugin - Upload the downloaded ZIP from Step 1.
- Activate the plugin through the 'Plugins' menu in WordPress.
- Set Up the Plugin as explained in the next Section.
Set Up
Before you can use this Plugin, you have to create an advanced custom field with the name "redirect_to_page_if_logged_in" and one with the name "redirect_to_page_if_not_logged_in".
- Install and activate the Advanced Custom Fields plugin.
- In the WordPress dashboard, go to Custom Fields > Add New.
- In the Field Label field, enter "Redirect to Page if Logged in".
- In the Field Name field, enter "redirect_to_page_if_logged_in".
- In the Field Type dropdown, select "Page Link".
- Now click "+ add Field" and repeat the last three steps with the label "Redirect to Page if NOT Logged in" and the name "redirect_to_page_if_not_logged_in".
- Click the "Publish" or "Save" button to save the custom field.
Usage
Static redirects
- Create a new page or edit an existing page.
- Set the value of the custom field you created in the
Set Upsection, by selecting the page you want to redirect to. - Save the page.
Dynamic redirects by url/query param
- If logged in users should be redirected:
a. Extend the link you use by the query param "redirect_logged_in" and the value of the url encoded redirect url.
b. Example: https://google.com/?redirect_logged_in=https%3A%2F%2Fgoogle.com%2Fusers - If logged out users should be redirected:
a. Extend the link you use by the query param "redirect_logged_out" and the value of the url encoded redirect url.
b. Example: https://google.com/?redirect_logged_out=https%3A%2F%2Fgoogle.com%2Flogin
Tip: An easy tool to generate URL encoded urls: https://www.urlencoder.org/
Deactivation
- Deactivate the plugin through the 'Plugins' menu in WordPress.
- Delete the plugin through the 'Plugins' menu in WordPress.
- If you want to you can also delete the Advanced Custom field and deactivate and delete the Advanced Custom Fields Plugin if you don't need it anymore.
License
The Automatic logged-in Page Redirect plugin is licensed under the GPL2 license. See the LICENSE file for more information.