• Resolved christ59620

    (@christ59620)


    Regarding my login page, my registered users are directed to their profile page, whereas I would like them to arrive on the main page of the site.
    I read the redirection code doc but I don’t know where to paste this code.

    thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Muhammad Arslan

    (@wparslan)

    Hey @christ59620

    May i know which do are you referring here?

    Do know, You have to copy and paste the code in the functions.php file of your child theme.

    If you need any assistance do let us know.

    Have a nice day!

    Thread Starter christ59620

    (@christ59620)

    Good morning,

    Thank you for your help.

    I was referring to this code addition.

    https://developer.www.ads-software.com/reference/hooks/login_redirect/

    Not being a child code of the theme, I will refer the addition to each modification of the theme (newspaper).

    Thanks again.

    Plugin Support Muhammad Arslan

    (@wparslan)

    Hey @christ59620

    You can use the following piece of code, It will redirect the admin user to the backend and all other user roles to the home page of the site.

    /**
     * Redirect user after successful login.
     *
     * @param string $redirect_to URL to redirect to.
     * @param string $request URL the user is coming from.
     * @param object $user Logged user's data.
     * @return string
     */
    function login_cust_login_redirect( $redirect_to, $request, $user ) {
    	//is there a user to check?
    	if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    		//check for admins
    		if ( in_array( 'administrator', $user->roles ) ) {
    			// redirect them to the default place
    			return $redirect_to;
    		} else {
    			return home_url();
    		}
    	} else {
    		return $redirect_to;
    	}
    }
    
    add_filter( 'login_redirect', 'login_cust_login_redirect', 10, 3 );

    If this doesn’t work for you, there might be some plugin or theme conflict which is also applying the redirection.

    Do let us know if this works for you.

    Have a nice day!

    Thread Starter christ59620

    (@christ59620)

    Thank you very much

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘redirection login’ is closed to new replies.