I'm making a login form for my site, and I've this section:

if (is_user_logged_in()) {
    echo 'Hello, ', $user_login, '. <a href="', wp_logout_url(), '" title="Logout">Logout</a>';
} else {

And after loggin in, it returns to the page with no indication of logging in.
I suspect is_user_logged_in() isn't working, but I don't know how to debug this problem.

EDIT: Whenever I do this:

global $current_user;

I always get:

ect(WP_User)#3 (7) { ["data"]=> NULL ["ID"]=> int(0) ["caps"]=> array(0) { } ["cap_key"]=> NULL ["roles"]=> array(0) { } ["allcaps"]=> array(0) { } ["filter"]=> NULL }

No matter if i've 'logged' in with the above form.

  • Disable all caching plugins and your browser cache. Does it still happen?
    – fuxia
    Commented Jul 18, 2012 at 10:49
  • Yeah, I tried deleting the cache. I should mention that I'm trying to implement wordpress into an existing website. So I don't really want to use any plugins or anything.
    – Adola
    Commented Jul 18, 2012 at 10:52

2 Answers 2


There's nothing wrong with the function, it's the fact that you aren't actually being logged in!

You say you're making your own login form? Does this post to the standard wp-login.php, or do you handle the request yourself?

Does the path/domain of the form differ from WordPress? If you inspect your cookies, are any being set?

  • I'm using wp_login_form() And as for path/domain, I'm not really sure. I'm using chrome, and according to the debugging profile thing, it suggests: Domain:localhost Path:/ Date:Fri, 10 Aug 2012 11:14:30 GMT Size:70
    – Adola
    Commented Jul 18, 2012 at 11:08
  • And for the form, it's stored in: http://localhost/newgameplus/TEST/scripts/php/testWP.php And the wordpress install is: http://localhost/newgameplus/wordpress/
    – Adola
    Commented Jul 18, 2012 at 11:09
  • 1
    I think that's the issue - WordPress will set a cookie with the path /newgameplus/wordpress/, which won't be read under /newgameplus/TEST/scripts/php/testWP.php. Try define( 'COOKIEPATH', '/' ); in your wp-config.php Commented Jul 18, 2012 at 11:53
  • By the way, I'd highly recommend using virtual hosts to develop on: wordpress.stackexchange.com/questions/32331/… Commented Jul 18, 2012 at 11:55

I know it is pretty late, but I am adding my answer to help others. If you use wp_signon() function to login, and verify with is_user_logged_in() thereafter, you need to set the current user with wp_set_current_user() first because wp_signon() does not handle setting the current user as described in the WP codex:


This is one of the reasons why the function is_user_logged_in() says false when you thought you have logged in a user already.

Your Answer

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

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