Title: Function Reference/is user logged in not working
Last modified: August 20, 2016

---

# Function Reference/is user logged in not working

 *  [hereintokyo](https://wordpress.org/support/users/hereintokyo/)
 * (@hereintokyo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/function-referenceis-user-logged-in-not-working/)
 * I have never had the need to use this function, but am building a new site that
   will rely on it heavily. I have tried adding the following code to the header:
 *     ```
       <?php
       if ( is_user_logged_in() ) {
           echo 'Welcome, registered user!';
       } else {
           echo 'Welcome, visitor!';
       }
       ?>
       ```
   
 * This always returns “Welcome, visitor!” even if I am logged in in the same browser
   and same session. I have tried every browser I have, with no success.
 * I tested this on some of my existing wordpress sites, and it works fine.
 * The new site I am making is on a different server. The other things that are 
   different are I have search engines blocked, and rather that have wordpress in
   the root folder, it is in a subfolder called “cms” but these do not seem to be
   causing any other problems.
 * Any ideas or suggestions would be appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [anmari](https://wordpress.org/support/users/anmari/)
 * (@anmari)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/function-referenceis-user-logged-in-not-working/#post-2135214)
 * Hmm
 * 1) – it’s a pluggable function – any other plugins altering the function?
 * 2) it just checks :
 *     ```
       $user = wp_get_current_user();
       	if ( $user->id == 0 )
       ```
   
 * try doing $user = wp_get_current_user(); yourself and dumping $user to see what
   is going on?
 * are you calling it in exactly the same place?
 *  Thread Starter [hereintokyo](https://wordpress.org/support/users/hereintokyo/)
 * (@hereintokyo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/function-referenceis-user-logged-in-not-working/#post-2135236)
 * Anmari, Thank you. I tried this
 *     ```
       $user = wp_get_current_user();
       $userid = $user->id;
       echo "User ID: " . $userid;
       ```
   
 * But this always returns the “User ID: 0” even if I am logged in.
 * My guess is this is an error caused by having my WordPress installation in a 
   subfolder called “CMS” has the session cookies all have the path /CMS/ Next I
   will try moving my installation to the root.
 * Thanks.
 *  [anmari](https://wordpress.org/support/users/anmari/)
 * (@anmari)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/function-referenceis-user-logged-in-not-working/#post-2135255)
 * Hi, I don’t think that’s it.
 * I don’t think wordpress uses sessions? and Many of my sites are in a sub folder
   and I have had no problem with that. WordPress itself uses that function all 
   over the place.
 * Maybe somehow it thinks you aren’t logged in yet? Page definitely refreshed after
   logon?
 * what is the wp version? Do you have admin bar functionality? Switch on for front
   end and check whether it is displayed at the top ?
 * The meta widget will also change if wp thinks you are logged in – drag it to 
   the sidebar of the page where your code is and check that when you are logged
   in it says “logout”
 *  Thread Starter [hereintokyo](https://wordpress.org/support/users/hereintokyo/)
 * (@hereintokyo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/function-referenceis-user-logged-in-not-working/#post-2135261)
 * Thanks. I tried adding the meta widget as you suggested. It shows “login” even
   if I am logged in.
 * In Firefox, if I delete the cookies for my site, and sign in, then there are 
   new cookies. What makes me think having the installation in a subfolder is the
   problem is that the cookies show the path of the installation folder, not of 
   the public side of the site.
 * I will try moving my installation to see if that helps.
 * Thanks.
 *  Thread Starter [hereintokyo](https://wordpress.org/support/users/hereintokyo/)
 * (@hereintokyo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/function-referenceis-user-logged-in-not-working/#post-2135454)
 * I moved my WP installation to the root rather than the subfolder CMS, and that
   worked. The cookies had the path /cms/ before the move, and now they have the
   path / which has fixed the problem.
 * I consider this a bug in WordPress, since putting your installation in a subfolder
   causes core functions to stop working.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Function Reference/is user logged in not working’ is closed to new replies.

## Tags

 * [login](https://wordpress.org/support/topic-tag/login/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 5 replies
 * 2 participants
 * Last reply from: [hereintokyo](https://wordpress.org/support/users/hereintokyo/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/function-referenceis-user-logged-in-not-working/#post-2135454)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
