Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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...

share|improve this question
add comment

2 Answers

If you only want to modify logout and not login, then use wp_logout_url(). Conversely you can use wp_login_url() for just the login URL.

Example of an logout link:

<a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Logout</a>

You can still use the function wp_loginout() but the redirect will work on both login and out. But if that is okay it could look like this:

<?php wp_loginout( home_url() ); ?>
share|improve this answer
    
Thanx Pontus, I hv tried with your code...but its not workin it goes to 404.php page... It is my second post but it's not solved my problem... plz help me... –  Gopal Bhattacharjee Jul 10 '12 at 14:57
add comment

Pontus Abrahamsson is right, that is a legal code, but here is another one that I'm using in my theme.

<a href="<?php echo wp_logout_url('$index.php'); ?>">Logout</a>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.