How to prevent redirect after login on WordPress

By default, WordPress redirects users to the admin dashboard after a successful login. If you want to prevent this redirect and send users to a different page, you can use the login_redirect filter.

To change the login redirect URL, follow these steps:

  1. Log in to your WordPress admin dashboard.
  2. Go to “Appearance” > “Theme Editor.”
  3. In the right sidebar, locate and click on the “functions.php” file.
  4. Add the following code snippet at the end of the file:
function custom_login_redirect($redirect_to, $requested_redirect_to, $user) {
    // Check if the user is successfully logged in
    if (!is_wp_error($user)) {
        // Set the desired redirect URL
        $redirect_to = home_url('/your-custom-page/');
    return $redirect_to;
add_filter('login_redirect', 'custom_login_redirect', 10, 3);

Replace /your-custom-page/ with the desired page URL slug or a different URL where you want to redirect users after login.

  1. Click “Update File” to save the changes.

This code snippet will redirect users to the specified page after a successful login. Remember to create a backup of your site before making changes to the code, as editing your theme’s functions.php file can have unintended consequences if not done correctly.

If you’re using a custom login form or a plugin that handles the login process, you may need to use a different method or consult the plugin documentation for preventing the default login redirect.

Leave a Reply

Your email address will not be published. Required fields are marked *