Users & Login PHP Beginner

Show a Message on the Login Page

Add a short message above the login form, such as a support link or a notice about scheduled maintenance.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 14 lines
add_filter( 'login_message', function ( string $message ): string {
	// Only on the main login screen, not on lost password or register.
	$action = isset( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : 'login';
	if ( 'login' !== $action ) {
		return $message;
	}

	$text = sprintf(
		'Trouble logging in? <a href="%s">Contact support</a>.',
		esc_url( home_url( '/support/' ) )
	);

	return $message . '<p class="message">' . wp_kses_post( $text ) . '</p>';
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

The login page is a good place for short, useful notes: where to get help, a reminder to use your work email, or a heads-up about planned downtime. This snippet adds one.

How it works

WordPress passes the message shown above the login form through login_message. The snippet adds a paragraph with the message class, so it uses the same blue notice style as WordPress’s own messages. It skips the lost password and register screens, which have their own messages.

Things to watch

  • Keep it short. Long text pushes the form down on phones.
  • Change the /support/ link to your own help page.

How to test it

Log out and open the login page. Your message should appear above the form.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only