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

When a user enters a page I want to check if he is logged in. How can it be done in the page's template? Or is it possible only in functions.php or a plugin?

share|improve this question
up vote 1 down vote accepted
if (is_user_logged_in())
    echo 'You are logged in. Yay!';

Codex: is_user_logged_in()

share|improve this answer
Thanks, Geert. Does this mean I can use all WP API elements (functions, hooks, filters) in a template? – Ash May 4 '11 at 11:36
Remember to accept correct answers – Mild Fuzz May 4 '11 at 12:19
And yes, you can use all the same functions, hooks and filters available in a normal page template – Mild Fuzz May 4 '11 at 12:20
@Ash: Template files are just like all PHP files, so yes, you have access to the complete WordPress API there. – Jan Fabry May 4 '11 at 12:24
Generally speaking, template tags, conditional tags, and public functions are all perfectly valid for use within template files. I would suggest, though, that hooks (and their callbacks), should be used only in functions.php. – Chip Bennett May 4 '11 at 12:38

Your Answer


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

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