WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

but problem is :

  1. redirect to 404 page not current page...
  2. I want to add user gavatar if he/she logged in

Any help greatly appreciated.

share|improve this question
Where are you using this snippet? get_permalink() without the post ID will only work inside the Loop. – Stephen Harris Jun 21 '12 at 9:04
A solution for cases get_permalink() does not work can be found at wordpress.org/support/topic/wp_loginout-return-to-current-page – Edi Goetschel Oct 23 '14 at 23:04

wp_loginout(get_permalink()); will make hyperlink with "Log out/Log in" text and after log out it will stay in the same page, or it will direct user to log in page.

share|improve this answer

something like this

function my_redirect(){
    $redirect_url = $_SERVER['HTTP_REFERER'];
    } else {
share|improve this answer
thanks... I add your code in function.php but not working. when user logout it should go to index.php '<a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>' '<a href="<?php echo wp_logout_url( get_bloginfo('url') ); ?>" title="Logout">Logout</a>' i used both code but not working...some thing missing – Gopal Bhattacharjee Jun 21 '12 at 14:34

For example:

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

Can all be done with WP functions - no custom code required in this case.

You just need to move the code from function.php into the theme and it should work.

share|improve this answer

Your Answer


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.