Creates a message to explain required form fields.
Source
function wp_required_field_message() {
$message = sprintf(
'<span class="required-field-message">%s</span>',
/* translators: %s: Asterisk symbol (*). */
sprintf( __( 'Required fields are marked %s' ), wp_required_field_indicator() )
);
/**
* Filters the message to explain required form fields.
*
* @since 6.1.0
*
* @param string $message Message text and glyph wrapped in a `span` tag.
*/
return apply_filters( 'wp_required_field_message', $message );
}
Hooks
- apply_filters( ‘wp_required_field_message’,
string $message ) Filters the message to explain required form fields.
Changelog
| Version | Description |
|---|---|
| 6.1.0 | Introduced. |
If you’ve changed the required indicator (
wp_required_field_indicator) from an asterisk (*) to (required) for accessibility reasons, you will also want to change the required field message to remove references to the glyph since it will be self-evident, so here’s a short snippet you can add tofunctions.phpto do it. This works with WordPress 6.9.4 (and probably others).There should be a span element inside the required message quotes for
$required_messageplus the first argument insprintf, but WP site’s formatting will not let me insert it because it strips out HTML presumably.