简体   繁体   English

WordPress用户登录重定向

[英]Wordpress user login redirect

I'm trying to redirect users to a certain page when logging in using the wordpress login on a certain page (there's a user/pass input on the homepage, not asking about redirect from site.com/wp-login). 在某个页面上使用wordpress登录名登录时,我试图将用户重定向到某个页面(主页上有用户/密码输入,而不是询问从site.com/wp-login进行重定向)。 The code is below; 代码如下; wpmem_ is from a plugin. wpmem_来自插件。 This code worked fine when I had a different URL but it's not working since I changed it to shop . 当我使用其他URL时,此代码可以正常工作,但由于将其更改为shop因此无法正常工作。

add_filter( 'wpmem_login_redirect', 'my_login_redirect', 10, 2 );

function my_login_redirect( $redirect_to, $user_id ) 
{
    // return the url that the login should redirect to
    return 'http://example.com/shop/';
}

If this is the function that gets called to redirect the user from the login, try to use the code below instead of the return function. 如果这是用来从登录名重定向用户的函数,请尝试使用下面的代码代替return函数。

header("Location: http://example.com/shop/");
exit();

Try this one: 试试这个:

add_filter( 'wpmem_login_redirect', 'my_login_redirect', 10, 3 );

function my_login_redirect( $redirect_to, $request, $user ) 
{
    // return the url that the login should redirect to
    return home_url('shop');
}

Insted of $_SERVER['HTTP_REFERER'] put your url where you want to redirect $_SERVER['HTTP_REFERER']插入,将您的网址放在您要重定向的位置

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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM