0

I've my login box on any page of my WordPress and I'm trying to redirect to the same page after a user logs in.

For example: If I make the login in the URL http://localhost/wordpress/category/sub-category/sold, redirect to the same URL.

I've this in my functions.php but, using my $url doesn't work.

How can make the redirection?

function login_go_home(){
    //$url ="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    wp_redirect(home_url());
    exit();
}
  • Are you using custom login form ? – CodeMascot Dec 13 '16 at 9:01
  • Answered here no? :wordpress.stackexchange.com/questions/125952/… – mayersdesign Dec 13 '16 at 9:05
  • I used something like the link @mayersdesign but isn't works – Marcos Dec 13 '16 at 10:08
  • No, I'm usign the Wordpress form @the_dramatist – Marcos Dec 13 '16 at 10:09
  • Then how you are showing the login form in particular pages ? Otherwise you need to go to wp-login.php first then login. Please share your login form code by which your user getting logged in. – CodeMascot Dec 13 '16 at 10:38
0

I need to do the next step:

To redirect my logout, I put the next code in functions.php

function out_home(){        
    wp_redirect(home_url());
    exit();
}
add_action("wp_logout","out_home");

In my header.php, to change the value of my URL in the login:

$URL_POSTLOGIN = add_query_arg(array(),$wp->request);
    function login_go_home($URL_POSTLOGIN){         
        wp_redirect($URL_POSTLOGIN);
        exit();
    }
    add_action("wp_login","login_go_home");

Maybe is not the best solution but in my case others codes fails.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.