Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use login_form_middle filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
February 20, 2023
5 minutes read

Ever wondered how to customize the login form in WordPress? Let’s talk about the login_form_middle filter! This filter is super handy as it allows you to inject content right after the login password field. Whether you want to add extra fields, messages, or anything else, this hook can help you out.

To use the login_form_middle filter, you need to register it using add_filter. You can place this code in the functions.php file of your active theme or in a custom WordPress Plugin. We at WePlugins always recommend creating a custom plugin to ensure your customizations remain intact even after theme updates.

In this guide, we’ll walk you through how to use the login_form_middle filter with some live examples. Let’s dive in!

Parameters

Below are the 2 parameters required to use this hook:

  • $content: (string) Content to display. Default empty.
  • $args: (array) Array of login form arguments.

Live Example 1: Basic Usage

Here is how you can use this hook to modify the login form content:

	function weplugins_modify_login_form_middle_defaults($content, $args) {
		// Update the $content variable according to your website requirements
		return $content;
	}
	// Add the filter
	add_filter("login_form_middle", "weplugins_modify_login_form_middle_defaults", 10, 2);
	

Live Example 2: Adding a Custom Message

How about adding a custom message below the password field?

	function weplugins_custom_login_message($content, $args) {
		$content .= '<p class="custom-message">Welcome to our site!</p>';
		return $content;
	}
	// Add the filter
	add_filter("login_form_middle", "weplugins_custom_login_message", 10, 2);
	

Live Example 3: Adding an Extra Field

Want to add an extra field to your login form? Here’s how:

	function weplugins_add_extra_login_field($content, $args) {
		$content .= '<p><label for="extra_field">Extra Field</label><input type="text" name="extra_field" id="extra_field" class="input" /></p>';
		return $content;
	}
	// Add the filter
	add_filter("login_form_middle", "weplugins_add_extra_login_field", 10, 2);
	

To remove a hook callback, use the example below:

	// Remove the filter
	remove_filter("login_form_middle", "weplugins_modify_login_form_middle_defaults", 10, 2);
	

Make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

Need help customizing your WordPress site?

Contact our WordPress Development Team and we’d be happy to assist you.

Access Premium WordPress Plugins

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.