将其粘贴到函数中。php文件并根据注释进行编辑。
add_filter(\'login_redirect\', \'redirect_user\', 10);
function redirect_user(){
global $user;
//where you want to redirect users too
$redirect = home_url() . \'/where-do-we-go-from-here/\';
/*
* each role listed in this array will be redirect to above URL
* if you only have one user role to redirect then simply remove
* the others.
*/
$role = array(
\'subscriber\',
\'another_role\',
\'etc\'
);
if ( in_array( $user->roles[0], array( \'administrator\') ) ) {
//admin will go to the dashboard
return admin_url();
} elseif ( in_array( $user->roles[0], $role ) ) {
return $redirect;
}
}
我应该补充一下,
$redirect = home_url() . \'/where-do-we-go-from-here/\';
//returns http://www.example.com/where-do-we-go-from-here/
也可以写为,
$redirect = home_url( \'/where-do-we-go-from-here/\' );
//returns http://www.example.com/where-do-we-go-from-here/
。。。函数的位置
home_url
接受路径作为其参数之一。