I have the following code that generates a login form for every page in my blog.
<form action="<?php echo wp_login_url(); ?>" method="post">
username: <br />
<input name="log" id="login_username" type="text" />
<br />
password: <br />
<input name="pwd" id="login_password" type="password" />
<br />
<br />
<input name="rememberme" id="rememberme" type="checkbox" value="forever" />
remember me
<br />
<br />
<input type="submit" value="login" />
<input type="hidden" name="redirect_to" value="/" />
<input type="hidden" name="testcookie" value="1" />
</form>
But it doesn’t work. It just lands the user in login page.
I’m wondering if I have left out a part of the form!
SOLVED: I should’ve just put a hidden input in the form with name of login
and some value like true
.
If you read the documentation on
wp_login_url
, you can specify a redirect URL without having to use that hidden input field. Alternatively, you could just use thewp_login_form
function to do exactly what you want:<?php wp_login_form(); ?>
Just toss that in there in place of your form, and read the documentation on that function to learn how to customize it.I should’ve just put a hidden input in the form with name of
login
and some value liketrue
.