user2209868 user2209868 - 2 months ago 8
PHP Question

WordPress login form code

I have the following in a WordPress sidebar widget that serves as an online community for my niche. Right now I am able to display the form when the user is not logged in and to display the "Welcome to the Community!" message when the user is logged out -- which is great. However, the login functionality doesn't seem to be working. Could I please get some help?



<form name="loginform" id="loginform" action="https://domain.org/wp-login.php"
method="post">
<p class="login-username">
<label for="user_login">Username</label>
<input type="text" name="log" id="user_login" class="input" value=""
size="20" />
</p>
<p class="login-password">
<label for="user_pass">Password</label>
<input type="password" name="pwd" id="user_pass" class="input"
value="" size="20" />
</p>
<p class="login-submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button-
primary" value="Log In" />
<input type="hidden" name="redirect_to"
value="https://domain.org/" />
</p>

</form>
<?php } else { ?>
<h4>Welcome to the Community!<h4>
<?php } ?>

Rob Rob
Answer

try this...

if (!is_user_logged_in()) {
    wp_login_form();
} else {
    echo '<h4>Welcome to the Community!</h4>';
}

You can also pass a configuration array to wp_login_form() See http://codex.wordpress.org/Function_Reference/wp_login_form