Skip to content

trepmal.com

  • Home
  • Plugins
  • Github
  • Me on WP.org
  • Donate

Categories

  • WordPress Bits (149)
  • Uncategorized (11)
  • Scripts (5)
  • Tidbits (5)
  • Fun (3)

Tags

  • wordpress (30)
  • administration (16)
  • plugin (9)
  • free download (8)
  • functions.php (8)

Year

  • 2018 (8)
  • 2016 (2)
  • 2015 (4)
  • 2014 (19)
  • 2013 (11)

Tag: log in

Add Log In/Out Links to Custom Menu

Sometimes you want to add a log in/out link (depending on whether the current user is logged in or not) in your main menu. Here’s a simple way to add them to the end.

add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
    if (is_user_logged_in()) {
        $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
    }
    else {
        $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
    }
    return $items;
}
Posted on April 30, 2011March 1, 2012Categories WordPress BitsTags custom menu, log in, log in/outLeave a comment on Add Log In/Out Links to Custom Menu

Allow Users to Log In with Registered Email Address

It seems to be more and more common to see sites that allow users to log in with their username or email address.

Here’s how to add that ability to WordPress

//remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
add_filter('authenticate', 'wp_authenticate_username_password_redux', 20, 3);
function wp_authenticate_username_password_redux( $user, $username, $password ) {
    if ( is_email( $username ) ) {
        $user_obj = get_user_by_email( $username );
        if ( $user_obj ) $username = $user_obj->user_login;
    }
    return wp_authenticate_username_password( $user, $username, $password );
}

* works with or without the remove_filter line.

Posted on April 27, 2011March 1, 2012Categories WordPress BitsTags authentication, log in1 Comment on Allow Users to Log In with Registered Email Address

Redirect Users to a Custom Log In Page

Relevant for WordPress 4.4: https://core.trac.wordpress.org/ticket/35103

If you’ve created a login page that isn’t at /wp-login.php, here’s a simple way you can redirect users who click on the “Log In” links to your new page:

add_filter( 'login_url', 'new_login_url', 10, 2 );
function new_login_url( $login_url, $redirect ) {
    return '/log-in/';
}
Posted on April 7, 2011December 16, 2015Categories WordPress BitsTags log in, redirect2 Comments on Redirect Users to a Custom Log In Page

Add the “Lost Password?” Link to wp_login_form() Output

If you’re using the handy wp_login_form() function to create a custom log in page, you may have noticed that you don’t get the “Lost Password?” link. Doesn’t take much to add it back:

add_action( 'login_form_middle', 'add_lost_password_link' );
function add_lost_password_link() {
	return '<a href="/wp-login.php?action=lostpassword">Lost Password?</a>';
}
Posted on April 6, 2011March 1, 2012Categories WordPress BitsTags log in14 Comments on Add the “Lost Password?” Link to wp_login_form() Output

Redirect Users at Login

Sometimes, it might be necessary to redirect users to some page other than the dashboard. In the example below, users are redirected to their profile page when they log in.

add_filter( 'login_redirect', 'redirect_to_profile', 10, 2 );
function redirect_to_profile( $redirect_to, $user ) {
    return admin_url('profile.php');
}
Posted on March 23, 2011March 1, 2012Categories WordPress BitsTags log in, redirectLeave a comment on Redirect Users at Login

Change the Login Screen Image

Normally, when you visit the login screen, there’s a nice WordPress image. If you want to change that to something else, this is how:

add_action('login_head', 'change_login_image');
function change_login_image() {
	$name = urlencode(get_option('blogname'));
	?><style type="text/css"> h1 a { background-image: url('http://dummyimage.com/310x70/f9/000&text=++<?php echo $name; ?>+'); } </style><?php
}
Posted on February 27, 2011March 1, 2012Categories WordPress BitsTags log inLeave a comment on Change the Login Screen Image
Proudly powered by WordPress