How to force all logged-out visitors in WordPress

By default, when a user logs out from a WordPress website, he or she will be taken back to the login page with a message notifying the user about successful logout.
But what if you want your users to be automatically redirected to your homepage after logout, I will use the wp_redirect
hook following the steps below:
Please ensure that you backup this file before pasting the code.
- Login to the WordPress admin panel.
- Click Appearance and then click Theme Editor.
- Select
functions.php
on the list of files. - Add an action to the
auto_redirect_after_logout
hook with the following code:
//Redirect function
function auto_redirect_after_logout(){
wp_redirect( home_url() );
exit();
}
//Fire action
add_action('wp_logout','auto_redirect_after_logout');
- Save changes.
- Logout and test.
This can also be achieved by using the Login and Logout Redirect plugin. The plugin adds an extra option in the Settings page ( Setting > General ), for specifying the redirect URL for login and logout.

Enter desired URLs, save changes and you’re done!