0

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.

1 Answer 1

2

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"; } ?> 
4
  • 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, 2012 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, 2012 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, 2012 at 13:47
  • Best way to know is trying.
    – kevin
    Jan 11, 2012 at 13:54

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.