You are here: Home » Wordpress » Redirect to referrer page after login in wordpress

Redirect to referrer page after login in wordpress

13 Flares 13 Flares ×

To redirect on referrer page after login in wordpress, use below code, paste this code in function.php.
There are many pluging to use a validation for a PAGE or POST. Only registered user can view such kind of POST and PAGE.
You may use simple access control plugin for it.
After login user can visit that POST or PAGE, which only for registered user.


if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) {
        add_filter('login_redirect', 'my_login_redirect', 10, 3);
        function my_login_redirect() {
                $location = $_SERVER['HTTP_REFERER'];
                wp_safe_redirect($location);
                exit();
        }
}

About Abhishek Sinha

I am Abhishek and I love to code on PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Scroll To Top
13 Flares Twitter 2 Facebook 1 Google+ 6 StumbleUpon 2 Pin It Share 0 LinkedIn 2 13 Flares ×