Determines whether the current visitor is a logged in user.
Description
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Source
}
endif;
if ( ! function_exists( 'is_user_logged_in' ) ) :
/**
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
Example: Display different output depending on whether the user is logged in or not.
Please note that
is_user_logged_in
is a pluggable function and you could get a fatal error if you call it too early.To solve this problem, you can wrap the login check within a function hooked to the init action:
Example: In case somebody want to add login and logout link in the template somewhere.
Example: From your functions file, this code displays a personal message for logged in users.
This function is more accurate if used at, or after, the ‘template_redirect’ Action. Before that, under unusual circumstances, it will give unexpected results.
The most common case is for a Site Address (URL) without a “www.” when an http:// request is received with a “www.” specified.
Background: between the ‘wp’ and ‘template_redirect’ Action, the Rewrite rules are applied for Pretty Permalinks. During this process, $_SERVER[‘SERVER_NAME’] is corrected in the common case listed above by removing “www.”