How to redirect users back to your protected files after login

Prevent Direct Access (PDA) Gold allows you to grant your protected files access to some specific users or user roles only. Unauthorized people will see your website 404 page or a customized “No Access” Page.

In many cases, you would like users to log in in order to access these files. Once they log in, you want to redirect them back to your protected file URL. You can achieve all of that with 2 simple steps below:

Step 1: Protect your private file with PDA Gold and select “Logged-in users” as file access permission.

Only “Logged-in users” are able to access this file

Step 2: Put this custom code snippet on your function.php file.

After users log in to your website, they will be redirected to your homepage by default. If you want to redirect them to the protected files that they have just tried to access, put the custom code snippet below at the bottom of your (child) theme’s function.php file:

Note: The first filter and function will override our “No Access Page” settings option. In case you want to redirect users to a custom login page, you should modify line 14 accordingly.

Non-logged-in users will see the login page when trying to access the protected file

You may want to refer to our blog post to understand more about how to redirect users back to your protected files after login.

Lasted updated on October 29, 2019