How Do I Redirect a User to the Home Page After Login in WordPress?

In order to redirect a user to the home page after login in WordPress, you will first need to create a function in your WordPress theme or plugin to handle the redirect. Once you have created the function, you will need to include the following code in it:

function redirect_after_login() { global $user; if ($user->user_login == ‘admin’) { return home_url(); } elseif($user->user_login == ‘user’) { return user_login_url($user->user_id); } else { return site_url(); } }

To use the function, you will need to include it in the wp_login_form() function in your theme or plugin. The wp_login_form() function will be called after the user has entered their login credentials. In the function, you will need to check to see if the user is logged in as admin or user.

If the user is logged in as user, you will return the user_login_url() function, which will return the user’s login page. If the user is logged in as admin, you will instead return the home_url() function, which will return the home page of your website.