I’ve recently launched some online journals for my two oldest daughters. Naturally, I set them up with a self-hosted private WordPress blog and built them each a quick customized theme (via Standard Theme).
Indoctrination?
No. I just want them to be using the best tools. 😉
These are simply for private use, so while I was monkeying around with privacy and login tweaks, I ran into a number of sweet login snippets I thought I’d share.
1. Display the login form in the theme.
This can be handy for so many uses. Not only can it simplify and streamline your sign-in, but is really handy for those who use subscription and membership based content.
To simply display the login form:
[cc lang=”php”][/cc]
Or, if you would like to define specific options:
[cc lang=”php”] ‘echo’ => true,
‘redirect’ => ‘http://wpsnipp.com’,
‘form_id’ => ‘loginform’,
‘label_username’ => __( ‘Username’ ),
‘label_password’ => __( ‘Password’ ),
‘label_remember’ => __( ‘Remember Me’ ),
‘label_log_in’ => __( ‘Log In’ ),
‘id_username’ => ‘user_login’,
‘id_password’ => ‘user_pass’,
‘id_remember’ => ‘rememberme’,
‘id_submit’ => ‘wp-submit’,
‘remember’ => true,
‘value_username’ => NULL,
‘value_remember’ => false );
wp_login_form($args);
?>[/cc]
Easy, right?
2. Redirect user after login.
I feel like such an idiot, right now.
About a year ago, I needed to do this. Instead of hunting down the code and manually doing it, I took the easy way out and found a plugin.
Tsk-tsk.
Add this to your functions.php:
[cc lang=”php”] add_action(‘login_form’, ‘redirect_after_login’);
function redirect_after_login() {
global $redirect_to;
if (!isset($_GET[‘redirect_to’])) {
$redirect_to = get_option(‘siteurl’);
}
}
?>[/cc]
Yup. It’s that easy.
3. Redirect back to referring page after login.
Have you ever logged into a private blog, and have to go through your user profile before heading to the site?
With this piece of beauty, the user is redirected back to the page they were originally trying to access.
Into the functions.php it goes:
[cc lang=”php”]if ( (isset($_GET[‘action’]) && $_GET[‘action’] != ‘logout’) || (isset($_POST[‘login_location’]) && !empty($_POST[‘login_location’])) ) {
add_filter(‘login_redirect’, ‘my_login_redirect’, 10, 3);
function my_login_redirect() {
$location = $_SERVER[‘HTTP_REFERER’];
wp_safe_redirect($location);
exit();
}
}[/cc]
This is slick, but what if you need options?
Next, please.
4. User controlled login redirect.
Now we’re getting fancy.
Drop this firecracker into your functions.php and the user can select their destination before clicking “Log In.”
Slick:
[cc lang=”php”] // Fields for redirect
function custom_login_fields() {
?>
‘;
return $message;
}
add_filter(‘login_message’, ‘custom_login_message’);[/cc]
😀
Bonus
These are great, but there are two other login that immediately come to mind that are really great.
First, my favorite:
The easy WordPress login URL. I’ve made this fairly standard for all of my WordPress installs.
The second, is for those of you that like a custom login screen. You know, you’re own logo, etc … A nice touch for your Church or client.
If you have any WordPress login mods you like to use, please, share!
[via WordPress Code Snippets]
Calum Henderson says
Cool tips Eric. Will definitely be bookmarking this for future use. Thanks!
Eric Dye says
Sweet!
kevin Chard says
Hey thanks for linking to my site glad you found it a good source of information.
Eric Dye says
Loving your site to death. You’ll see some more links, I think 😉