在wordpress登录后尝试将用户重定向到主页

时间:2021-11-19 02:51:18

As the title says, I am trying to redirect users, after they log in, back to the homepage. Here is the function I have in functions.php:

正如标题所说,我试图在用户登录后重定向回主页。这是我在functions.php中的函数:

function redirect_to_front_page() {
wp_redirect( get_option('home') );
}

add_action('wp_login', 'redirect_to_front_page');

For some reason I just get redirected to the login form.

出于某种原因,我只是被重定向到登录表单。

Sorry for the simple question, still quite new to wordpress

对不起这个简单的问题,对wordpress来说还是一个新手

Thanks in advance

提前致谢

1 个解决方案

#1


0  

Here's one way of doing it:

这是一种方法:

function redirect_to_front_page($redirect_to, $request, $user) {
    return (is_array($user->roles) && in_array('administrator', $user->roles)) ? admin_url() : site_url();
} 
add_filter('login_redirect', 'redirect_to_front_page', 10, 3);

Note that it's making sure it's not an administrator before redirecting the user.

请注意,在重定向用户之前,它确保它不是管理员。

#1


0  

Here's one way of doing it:

这是一种方法:

function redirect_to_front_page($redirect_to, $request, $user) {
    return (is_array($user->roles) && in_array('administrator', $user->roles)) ? admin_url() : site_url();
} 
add_filter('login_redirect', 'redirect_to_front_page', 10, 3);

Note that it's making sure it's not an administrator before redirecting the user.

请注意,在重定向用户之前,它确保它不是管理员。