Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Show login to users not logged in &welcome message when they are WordPress

  • SOLVED

I have the login looking pretty much how I want it to look, and it works. However, when a user logs in, it still has the login in form up there.

What I'd like to do is have the login form for users not logged in, but when ther are logged in, show some kind of welcome message.

Here is the temp site:

http://joe.gs

Answers (3)

2010-08-14

Baki Goxhaj answers:

Hi Joe,

This code will do the magic:


<?php
if ( is_user_logged_in() ) {

echo 'Welcome!';

} else {

// Your form's code goes here

};
?>


Joe Jenkins comments:

Thanks Baki,

That seems straight forward but, of course being me, there has to be an error turn up.

I'm using the following code:

<?php

if ( is_user_logged_in() ) {
echo 'Welcome!';

} else {
<?php wp_login_form(); ?>

};
?>


But I get a white screen error telling me:

<strong><em>Parse error: syntax error, unexpected '<' in /var/www/vhosts/joe.gs/httpdocs/wp-content/themes/Bloggers/header.php on line 41</em></strong>

Line 41 is the php login form code. It works fine on its own.


Joe Jenkins comments:

Ah, leave off the php bits inside php.

That sorted it, thanks :o)


Baki Goxhaj comments:

You have opening PHP tags insde PHP. Do this:


<?php

if ( is_user_logged_in() ) {

echo 'Welcome!';

} else {

wp_login_form();

};

?>

2010-08-14

Rashad Aliyev answers:

I gave you a code which made by me for other projects.

You can integrate it your site. It's showing login form and if it's logged then show Welcome message, profile links and logged out. You can improve it.

<?php if (!(current_user_can('level_0'))){ ?>


<h3>Login</h3>
<form action="<?php echo get_option('home'); ?>/wp-login.php" method="post">
<input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="20" />
<input type="password" name="pwd" id="pwd" size="20" />
<input type="submit" name="submit" value="login" class="button" />
<p>
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember</label> | <a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">forget password (?)</a>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
</p>
</form>

</div>

<div align="center" ><a id="girisbutton-a" href="<?php echo get_option('home'); ?>/wp-login.php?action=register">register</a></div>

<?php } else { ?>
<div><h3><?php echo $user_identity; ?></h3>
<div><a href="<?php echo wp_logout_url(urlencode($_SERVER['REQUEST_URI'])); ?>">log out»</a></div>

Welcome! </div>

<a id="girisbutton-a" href="<?php echo get_option('home'); ?>/wp-admin/profile.php">look at profile</a>
<?php }?>

2010-08-14

Ashfame answers:

Use this : <?php

if ( is_user_logged_in() )
{
echo 'Welcome!';
}
else
{
wp_login_form();
}

?>