Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp signon


Authenticates a user with option to remember credentials. Replaces deprecated function wp_login.


 <?php wp_signon$credentials$secure_cookie ?> 


(array) (optional) User info in order to sign on.
Default: None
(boolean) (optional) Whether to use secure cookie.
Default: None

NOTE: If you don't provide $credentials, wp_signon uses the $_POST variable (the keys being "log", "pwd" and "rememberme").

Return Value

Either WP_Error on failure, or WP_User on success.


This function and action can be placed in functions.php of the theme. Using the hook after_setup_theme will make it run before the headers and cookies are sent, so it can set the needed cookie for login.

function custom_login() {
	$creds = array();
	$creds['user_login'] = 'example';
	$creds['user_password'] = 'plaintextpw';
	$creds['remember'] = true;
	$user = wp_signon( $creds, false );
	if ( is_wp_error($user) )
		echo $user->get_error_message();
// run it before the headers and cookies are sent
add_action( 'after_setup_theme', 'custom_login' );


  • This function sends headers to the page. It must be run before any content is returned.
  • This function sets an authentication cookie. Users will not be logged in if it is not sent.

Change Log

Since: 2.5.0

Source File

wp_signon() is located in wp-includes/user.php.


See also index of Function Reference and index of Template Tags.