[英]Attempting to redirect users to home page after wordpress login
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 提前致谢
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. 请注意,在重定向用户之前,请确保它不是管理员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.