Logout redirect to home page

I’m using custom menu for login/logout here below is my code:

<li>
      <?php
if (is_user_logged_in()) {
  $user = wp_get_current_user();
  echo 'Welcome <strong><a href="http://kolkataonwheelsmagazine.com/wp-admin/index.php" >'.$user->user_firstname.'</a></strong>
  | <a  href="http://kolkataonwheelsmagazine.com/wp-login.php?action=logout&quot;">Logout</a>';
} else { ?>
  <strong><?php wp_loginout(); ?></strong>
  or <a href="<?php bloginfo('url') ?>/wp-login.php?action=register"> <strong>Register</strong></a>
<?php }?>
    </li>

but problem is :

redirect to login page not current page…

I want it should go to home page after logout.
Please help me…

6 s
6

add_action('wp_logout','auto_redirect_after_logout');

function auto_redirect_after_logout(){
  wp_safe_redirect( home_url() );
  exit;
}

This will do the trick.

Leave a Comment