WordPress / Web Development Tutorials
(Best WordPress Tutorials)

CSSHTMLJavaScriptjQueryMySQLPHPSilvaTechnologiesWooCommerceWordpress
Silva Web Designs - Blog

How To Auto Redirect Users After Logout In WordPress

This is a useful trick if you’re developing a website for client on WordPress and want to manually redirect users after logout of your WordPress website. By default, WordPress will redirect them to the login page of your website, but we can easily change it by adding following snippet to the current theme’s functions.php file:


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

The above code snippet will redirect your users to the homepage of your website. You can also define a custom URL or external URL by adding the following snippet:


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

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development, website design and basically anything digital-related. His main expertise is with WordPress and various other CMS frameworks. If you need responsive design, SEO, speed optimisation or anything else in the world of digital, you can contact Silva Web Designs here; [email protected]

It’s good to share

Join the discussion