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:

<?php
   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
1  
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

3 Answers 3

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

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

something like this

function my_redirect(){
    $redirect_url = $_SERVER['HTTP_REFERER'];
    if(!empty($_REQUEST['redirect_to'])){
        wp_safe_redirect($_REQUEST['redirect_to']);
    } else {
        wp_redirect($redirect_url);
    }
    exit();
}
add_filter('wp_logout','my_redirect');
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

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.