Assigns a visual indicator for required form fields.
Source
function wp_required_field_indicator() {
/* translators: Character to identify required form fields. */
$glyph = __( '*' );
$indicator = '<span class="required">' . esc_html( $glyph ) . '</span>';
/**
* Filters the markup for a visual indicator of required form fields.
*
* @since 6.1.0
*
* @param string $indicator Markup for the indicator element.
*/
return apply_filters( 'wp_required_field_indicator', $indicator );
}
Hooks
- apply_filters( ‘wp_required_field_indicator’,
string $indicator ) Filters the markup for a visual indicator of required form fields.
Changelog
| Version | Description |
|---|---|
| 6.1.0 | Introduced. |
To save someone else the trouble of trying to figure out how to change asterisks (*) as the required field indicator to the word (required) for accessibility reasons, here is one which works with WordPress 6.9.4 (and probably others). It is in a span element (WP site formatting removes spans so put it around the (required) in
$required_indicatorso you need to add it) so you can restyle the size of the text in CSS if you like.This also requires changing
wp_required_field_message()so I will add a note to that hook as well.