登录后重定向到当前URL

时间:2016-12-13 作者:Marcos

我在WordPress的任何页面上都有我的登录框,我试图在用户登录后重定向到同一页面。

例如:如果我在URL中登录http://localhost/wordpress/category/sub-category/sold, 重定向到同一URL。

我把这个放在我的functions.php 但是,使用我的$url 不起作用。

如何进行重定向?

function login_go_home(){
    //$url ="http://".$_SERVER[\'HTTP_HOST\'].$_SERVER[\'REQUEST_URI\'];
    wp_redirect(home_url());
    exit();
}

1 个回复
SO网友:Marcos

我需要执行下一步:

为了重定向我的注销,我将下一个代码放入函数中。php

function out_home(){        
    wp_redirect(home_url());
    exit();
}
add_action("wp_logout","out_home");
在我的标题中。php,要更改登录中我的URL的值,请执行以下操作:

$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");
也许不是最好的解决方案,但在我的情况下,其他代码会失败。