
Are you using WordPress as a cms or as a community site? If yes, it can be a cool idea to display a login form in your blog sidebar or on a specific page. Here’s a simple code to do it.

Are you using WordPress as a cms or as a community site? If yes, it can be a cool idea to display a login form in your blog sidebar or on a specific page. Here’s a simple code to do it.
Nothing hard at all. Simply paste the following code where you'd like to display your login form. (For example, on your blog sidebar, or on a page template)
<<?php if (!(current_user_can('level_0'))){ ?>
<h2>Login</h2>
<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="Send" class="button" />
<p>
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
</p>
</form>
<a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">Recover password</a>
<?php } else { ?>
<h2>Logout</h2>
<a href="<?php echo wp_logout_url(urlencode($_SERVER['REQUEST_URI'])); ?>">logout</a><br />
<a href="http://XXX/wp-admin/">admin</a>
<?php }?>
Once saved, your theme will display a login form. Definitely easier and quicker for login!
4 Responses
I used this code but I think there is some error…
I can see the login box in my sidebar but the login field is not empty but show this line:
how can you fix this?
Thanks!
You can see that there is an extra “<" at the beginning of this code. Remove it and all should be fine.
@luca: I think there is an extra < in the beginning of the code. I haven't tried the script but it should start <?php not <<?php
hey
that’s probably a very wimpy question,
but would somebody please tell me how to create the function that users have to use a login&password to read my wordpress blog?
thx!
Trackbacks: