是否有一个功能允许您更改登录后重定向到的位置?
我正在登录标准的Wordpress登录表单,将您重定向到仪表板,有没有办法更改它,以便您重定向到页面列表?
重要的是我不是在编辑核心WP文件(尽管很简单,但它要求麻烦!)并通过一个函数来完成.
这不是任何类型的前端登录,它只是将标准WP登录屏幕从仪表板重定向到页面列表 - wp-admin/edit.php?post_type = page(因为我不喜欢这些信息)显示在仪表板上).
将其添加到您的主题functions.php:
function my_login_redirect( $redirect_to, $request, $user ){
//is there a user to check?
global $user;
if( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if( in_array( "administrator", $user->roles ) ) {
// redirect them to the default place
return home_url(); //admin redirect url
} else {
return admin_url( 'edit.php?post_type=page' ); //user redirect url
}
}
else {
return $redirect_to;
}
}
add_filter("login_redirect", "my_login_redirect", 10, 3);
Run Code Online (Sandbox Code Playgroud)
这将在登录后将用户重定向回主页.通过上述操作,您可以将管理员重定向到单独的位置(如果需要,可以将仪表板),然后将其他用户重定向到您的自定义URL.