Using WordPress ‘login_header()’ PHP function

The login_header() WordPress PHP function outputs the login page header with a custom title, message, and error handling.

Usage

login_header( 'Custom Login', 'Welcome to the Custom Login Page', $errors );

Parameters

  • $title (string) Optional: The WordPress login page title to display in the <title> element. Default: ‘Log In’
  • $message (string) Optional: Message to display in the header. Default: ”
  • $wp_error (WP_Error) Optional: The error to pass. Default is a WP_Error instance. Default: null

More information

See WordPress Developer Resources: login_header()

Examples

Custom Login Page Title

Display a custom login page title in the <title> element.

login_header( 'Member Login' );

Custom Message in Header

Display a custom message in the header.

login_header( 'Log In', 'Welcome to our website!' );

Custom Error Message

Display a custom error message using WP_Error.

$errors = new WP_Error();
$errors->add( 'invalid_login', 'Incorrect username or password.' );
login_header( 'Log In', '', $errors );

Reset Password Page

Create a reset password page with a custom title and message.

login_header( 'Reset Password', 'Enter your new password below.', $errors );

Custom Error Handling

Create a custom login page with error handling for invalid credentials.

$errors = new WP_Error();
if ( isset( $_GET['login'] ) && $_GET['login'] == 'failed' ) {
    $errors->add( 'invalid_login', 'Invalid username or password.' );
}
login_header( 'Log In', '', $errors );