How to Redirect to Custom URL After Logout in WordPress
In WordPress, it’s common to redirect users to a specific page after they log out, such as the login page, the homepage, or a custom page. Redirecting users to a custom URL after logout in WordPress can offer several benefits, including improved user experience and providing a clear next step for users after they log out. This article will guide you through the process of redirecting users to a custom URL after logout in WordPress. This will work with woocommerce also.
Why Redirect to Custom URL After Logout in WordPress?
When a user logs out of your WordPress site, it’s important to provide a clear next step for them. Redirecting users to a custom URL after logout in WordPress can offer several benefits, including:
Improved User Experience: By redirecting users to a custom URL after logout, you can provide a seamless and consistent experience for your users. This can help improve the overall user experience on your WordPress site and make it easier for users to find what they need.
Custom Message or Information: You can provide a custom message or information to your users. For example, you can redirect users to a custom page that provides information about your site, your services, or your contact information.
Better Branding: You can reinforce your brand and promote your services. This can help improve brand recognition and increase the chances of users returning to your site in the future.
Better Security: By redirecting users to a custom URL after logout, you can ensure that sensitive information is protected. For example, you can redirect users to a custom page that warns them about the dangers of public Wi-Fi or reminds them to log out on public computers.
Steps to redirect to custom URL after logout
Please note that do the customization in your child theme. If you haven’t yet created child theme then read this article to create one. If you do not want to edit functions.php file then install a plugin Code Snippets by Code Snippets Pro, and add the code by using this plugin.
Step 1: Access functions.php file.
Go to Appearance > Theme File Editor > Theme Functions (functions.php). Below is the image for your reference.
Step 2: Add below code.
Copy below code and paste at the end of functions.php file.
// redirect to custom url after logout
function wpamit_redirect_to_custom_url_after_logout() {
$redirect_url = 'https://woo.wpamit.com/product-category/men/';
wp_redirect($redirect_url);
exit;
}
add_action('wp_logout', 'wpamit_redirect_to_custom_url_after_logout');
Note: Replace https://woo.wpamit.com/product-category/men/
in highlighted line with the URL of the custom page you want to redirect users to after logout.
Step 3: Test the Redirection
Finally, test the redirection by logging out of your WordPress site. You should be redirected to the custom URL after logout.
Conclusion
By following these steps, you can easily redirect users to custom URL after logout in WordPress. This method uses WordPress’ built-in functions and hooks, and it provides a simple and reliable way to redirect users to custom URL or page after they log out. This can help improve the user experience on your WordPress site and provide a clear next step for users after they log out.
More Articles:
How to Redirect Users to the Previous Page Upon Login in WordPress.
Change WordPress Login Logo without Plugin.
Restore WordPress Classic Widget Editor.
Good it’s working