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.

Basically I'm putting together a magazine site that wants a strong focal point on the homepage for users who haven't signed up, if the user is logged in we need this content to show something else, is this possible?

Basically I need a function to show X if the user is logged in and if not to show Y, the code will be placed in the header so whatever page the user has landed on it will encourage the viewer to register for an account.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Yes it's possible, just use the is_user_logged_in() function as descibed in the codex for this.

It would go like this:

<?php if ( is_user_logged_in() ) { echo "you are logged."; } else { echo "You are not logged"; } ?> 
share|improve this answer
    
Can you echo the users name with that code? Also the message for not logged in users will need to contain a login form, is that possible? –  Dave Burns Jan 11 '12 at 13:03
    
You can use the get currentuserinfo() function to retrieve infos about the user currently viewing the page: codex.wordpress.org/Function_Reference/get_currentuserinfo Yes you can add anything in the else{} statement. You can close the php tag right after the '{' and put as much html as you want. –  kevin Jan 11 '12 at 13:14
    
Is it safe to say that the following code would do the job? <?php if ( is_user_logged_in() ) { include (TEMPLATEPATH . '/welcome.php'); } else { include (TEMPLATEPATH . '/register.php'); } ?> –  Dave Burns Jan 11 '12 at 13:47
    
Best way to know is trying. –  kevin Jan 11 '12 at 13:54

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.