How to Redirect Users to Homepage After Logout in WordPress (No Plugin Way)

Last updated on Apr 23, 2025

The default WordPress configuration will redirect all logged in users to the login page when they log out. Is there a way to change this? Yes, of course. WordPress allows you to do anything to your website.

In this post, I will show you how to redirect logged in WordPress users to the homepage after they log out. No extra plugin involved.

I will show you the manual method by adding a simple code snippet which you can add to your WordPress website.

Before getting started, let’s find out when and why you will need to redirect users to the homepage after logout. If you want to go straight to the code snippet, you can use the shortcuts below.

Shortcuts ⤵️

When Do You Need to Redirect Users to Homepage?

As you know, you can create nearly all types of websites you can think of with WordPress thanks to the abundance of the plugins available.

One of the website types you can create with WordPress is a membership website.

One of the crucial features you need to add to your membership website is the ability for your members to login to the backend (dashboard).

Most WordPress membership plugins like ProfilePress and Ultimate Member already have a built-in feature to create a custom login page.

However, some of them don’t offer a setting option to redirect users to the homepage or a certain page after logout. Users will still be redirected to the login page after log out, which is not a good experience.

Or,

You may want to offer a different login experience to your members.

Instead of via the login page, you may want to offer a login experience via a popup, which you want to show up when members click a login button on the header (or any location).

In the scenario above, hiding the login page is a must, then.

Redirecting Users to Homepage After Logout

As I said earlier, I will show you how to redirect logged in users to the homepage after they logout without involving a plugin. Instead, I will use the custom code approach in this post.

To be able to add custom code, you need to have access to the funtions.php file of your active theme. You can access and edit the file either directly on your WordPress dashboard or via the control panel of your hosting provider.

Before you start, I strongly recommend you to create a backup of your website first just in case everything doesn’t go as per expectation.

Or if you use one of the following hosting services:

You don’t need to backup your website yourself as they perform automatic backup on a daily basis. You can go straight to the next step below.

Adding the Code Snippet

Here is the code snippet you need to add to redirect users to te homepage after logout in WordPress:

add_action('wp_logout','auto_redirect_after_logout');
function auto_redirect_after_logout(){
  wp_safe_redirect( home_url() );
  exit();
}

How to add the code above?

First, login to your WordPress dashboard and go to Appearance -> Theme File Editor.

⚠️ If you are a block theme user, you can find Theme File Editor under the Tools menu.

Theme file editor

If you can’t find Theme File Editor on your WordPress dashboard, try to check the settings on your security plugin. Some security plugins, including Security Optimizer, disable Theme File Editor on the default settings.

On the Theme File Editor screen, select the functions.php file on the right panel to edit it. Paste the code above right after the last line of the functions.php file content and click the Update File button.

Adding custom function in WordPress

Try to logout from your WordPress dashboard after updating the file above and you should now be redirected to the homepage.

Alternative Method to Add Custom Function in WordPress

Editing the functions.php file of the active theme is the easiest way to add a custom function in WordPress. But you also need to understand that it is the least effective way because your theme will override your custom code when you update your theme.

Two options you can choose if you want to add a permanent custom function are:

  • By creating a child theme
  • By creating a custom plugin dedicated to hosting custom functions

I personally recommend the second option because it is easier to do. Also, creating a custom plugin allows you to add multiple custom functions more easily in the future. And you only need to manage one file.

You can jump to this section to learn more about how to create a custom plugin to host custom functions.

Redirecting Users to a Specific Page After Logout (BONUS)

Instead of the homepage, you may want to redirect your users to a specific page after they logout. Is that possible too? Yes, of course.

You can follow the same steps above to redirect users to a specific page after logout. But you need to edit the code.

And the code snippet you can use for this particular purpose is:

add_action('wp_logout','auto_redirect_external_after_logout');
function auto_redirect_external_after_logout(){
  wp_redirect( 'https://www.yourcustomurl.com' );
  exit();
}

You can replace the URL inside the single quote marks with the URL of the page you want to redirect your users to.

For instance, if I want to redirect my users to the about page on this website, then I can replace https://www.yourcustomurl.com with https://utilizewp.com/about/.

You can use the snippet above to force your users to view a certain page (e.g., an upsell page) on your website after they logout.

Summary

WordPress allows you to do anything to your website, including changing the default configuration to improve user experience.

If you run a membership website, you may want to increase login experience by displaying the login form in a popup instead of a page. And for this, you need to hide the login page.

However, hiding the login page alone will be useless if you don’t change the default WordPress configuration which redirects users to the login page after logout.

If you don’t edit this default configuration, users will still know that the login page exists on your website. You can use the one of the code snippets above to redirect users to either homepage or a specific page on your website after they logout.

And to add the code, you can either edit the functions.php file of your active theme or create a custom plugin dedicated to hosting custom functions.

This page may contain affiliate links, which help support the project. Read our affiliate disclosure.

Aliko Sunawang

Aliko is a professional blogger and web creator. He has been blogging with WordPress since 2013. In his spare time, he loves going out to take some photos. More

Got WordPress knowledge?

Why not turn it into profit?

new

Got a website?

You might need this cool content to boost your organic traffic from Google.

Where should we send the template?

Thanks! Please check your inbox to confirm.