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

share|improve this question
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 '13 at 13:46
@s_ha_dum, get_current_user_id is used in static pages. Let me recheck . – Istiaque Ahmed Oct 23 '13 at 12:54

Your Answer


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

Browse other questions tagged or ask your own question.