Wordpress redirect to homepage after successfully logged in

33 views Asked by At

When I try to log in to my WordPress website through /wp-admin, or /wp-login after entering the correct login and password details, it will redirect to the homepage rather than to the dashboard. I have tried the following:

  1. Disable all plugins.
  2. Changed theme from generatepress to default wp theme.
  3. restore .htaccess file to basic settings.
  4. repaired database from wp toolkit from c panel.
  5. Delete browser cache (Google Chrome)
  6. Checked (go through) the wp-config file code to see any additional code.

I have tried all possibilities one by one and again and again with no result.

1

There are 1 answers

4
mokorana On

Here’s an example of what it might look like:

add_filter( 'login_redirect', 'custom_login_redirect', 10, 3 );
function custom_login_redirect( $url, $request, $user ) {
    if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
        if ( $user->has_cap( 'administrator' ) ) {
            $url = home_url();
        }
    }
    return $url;
}

Note: You have to put this code into your functions.php