Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.