Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Redirect user after login

0

I am trying to redirect my users to the last visited page after they logged in on my custom login page, but after users logged in they stay on the login page, and I think it is because of my redirect I have added on my custom login page. Can someone please advise on this? Thank you.

This is my Login redirect on all pages to go to the login page:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


function admin_redirect() {

    if ( !is_user_logged_in() ) {
        wp_redirect( home_url('member-login') );
        exit;
     }
};
add_action('get_header', 'admin_redirect');








And this is my function I try to redirect to last visited page, if users click on a article for example, to view it if they login. But it is still going to the 'member-login':


function admin_default_page($attributes) {
$attributes = isset($_SERVER[‘HTTP_REFERER’]) ? $_SERVER[‘HTTP_REFERER’] : ‘/member-login’;
return $attributes;
}

add_filter(‘login_redirect’, ‘admin_default_page’);



>Solution :

function admin_redirect() {

if (is_user_logged_in() ) {
    echo "<script>history.go(-1);</script>";
 } else:
    wp_redirect( home_url('member-login') );
    exit;

};

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading