Redirect code not executing
-
Hi everyone
My site is using the latest WordPress 6.8.2 with WordPress 2025 theme and BBPress community
In
27. Custom Redirect After LoginAt address
The following dual-purpose redirect code:
/**
* WordPress function for redirecting users on login based on user role
*/
function my_login_redirect( $url, $request, $user ){
if( $user && is_object( $user ) && is_a( $user, ‘WP_User’ ) ) {
if( $user->has_cap( ‘administrator’ ) ) {
$url = admin_url();
} else {
$url = home_url();
}
}
return $url;
}
add_filter(‘login_redirect’, ‘my_login_redirect’, 10, 3 );It is introduced that I have it in the php sippet file of the WordPress plugin code but I am getting the error
Your changes are saved but your snippet was deactivated due to an error, please check the syntax and try again. Error message: syntax error, unexpected token ;
It seems that there is a problem with the code.
Can anyone help to fix the problem?
- You must be logged in to reply to this topic.