Filter the HTML of the Contact Form.
Parameters
- $rendered_field
string Contact Form HTML output.
- $field_label
string Field label.
- $id
(int | null) Post ID.
Changelog
- Introduced in Jetpack 2.6.0
How to use this hook
Notes
This snippet adds autocomplete=”email” to the email input field, enabling autofill support from browsers and password managers:
add_filter( 'grunion_contact_form_field_html', function( $rendered_field, $field_label, $id ) {
if ( $field_label === 'Email' ) {
$rendered_field = preg_replace(
'/<input/',
'<input autocomplete="email"',
$rendered_field,
1
);
}
return $rendered_field;
}, 10, 3 );
This pattern can be extended to other fields by modifying the $field_label check or changing the inserted attributes.