2

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.

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

1

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');
1
  • 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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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