• I have a WP install on a single domain and some custom PHP pages not part of WP but in the root folder. When the pages are accessed directly I want it to check if the user is logged in or not, which I currently have

    <?php
    require('../wp-load.php');
    get_header();
    if ( is_user_logged_in() ) {
       echo "Welcome, Registered User";
    } else {
    	header("Location:../wp-login.php?location=" . urlencode($_SERVER['REQUEST_URI']));
    	exit;
    }
    ?>

    This function is on the page I want protected and it works. What it does is checks if the end user viewing the page is logged in. If the end user is logged in the text, “Welcome, Registered User”, is shown and then the page contents. If not authenticated, the page redirects to the login page and the url displays “https://www.mydomain.com/wp-login?location=%2Fsubfolder%2Fmypage.php&#8221;

    How can I get that url to redirect after successful login to https://www.mydomain.com/subfolder/mypage.php

    ??????ANY THOUGHTS????

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter drew4663

    (@drew4663)

    Hello????

    Thread Starter drew4663

    (@drew4663)

    I found out the answer. All you need to do is place the following code into the non-wordpress page you would like to check for authentication and after login it will redirect you to the page you were previously on.

    <?php
    require('../wp-load.php');
    get_header();
    php auth_redirect();
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP Login redirecting to previously visited page’ is closed to new replies.