Skip to:
Content
Pages
Categories
Search
Top
Bottom

Redirect code not executing

  • @ar_m

    Participant

    Hi everyone

    My site is using the latest WordPress 6.8.2 with WordPress 2025 theme and BBPress community

    In
    27. Custom Redirect After Login

    At address

    Layout and functionality – Examples you can use

    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?

Viewing 1 replies (of 1 total)
  • @robin-w

    Moderator

    now corrected in codes, to this

    /**
    * 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 );
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar