0

I added a login, logout menu item to a menu with the following code in functions.php. After logout it redirects to the current page. But surprisingly enough, the get_current_user_id method still holds the value of the previously logged in user.

add_filter( 'wp_nav_menu_items', 'asv_add_usermenu_student', 10, 2 );

     function asv_add_usermenu_student( $items, $args ) {

              if (is_user_logged_in() && $args->theme_location == 'top_student_menu') {

                $items .= "<li ><a href='" .wp_logout_url( get_permalink() ). "'>Log Out</a></li>";

            } elseif (!is_user_logged_in() && $args->theme_location == 'top_student_menu') {

               $items .= '<li > <a href="' . wp_login_url() . '?redirect_to='.$_SERVER["REQUEST_URI"].'"/>LOG IN</a></li>';
              }
              return $items;
            }

How to grt rid of it ?

2
  • get_current_user_id does not show up anywhere in your code and the user ID does not persist when I test this. There is something wrong somewhere in code not posted.
    – s_ha_dum
    Oct 15, 2013 at 13:46
  • @s_ha_dum, get_current_user_id is used in static pages. Let me recheck . Oct 23, 2013 at 12:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.