Riassunto AI
Desideri personalizzare le sottodescrizioni associate ai tuoi campi Password? Con poche righe di codice PHP, puoi adattare facilmente queste etichette per allinearle meglio alle tue esigenze.
I campi password includono comunemente sottodescrizioni sotto di essi, specialmente quando l'opzione Abilita conferma password è attiva. Questa funzionalità assicura che gli utenti confermino le loro password inserendole due volte. Tuttavia, le sottodescrizioni predefinite potrebbero non corrispondere sempre perfettamente al messaggio o al branding desiderato.

In questo tutorial, ti mostreremo come usare PHP per cambiare il testo di queste sottodescrizioni.
Creazione del modulo
Per prima cosa, inizieremo creando il nostro modulo e aggiungendo i nostri campi. Aggiungeremo anche il campo modulo Password e abiliteremo Abilita conferma password.

Se hai bisogno di aiuto nella creazione del tuo modulo, esamina questa documentazione.
Modifica delle sottodescrizioni della password
Per modificare il testo che appare sotto il campo modulo Password, dovremo aggiungere questo snippet al nostro sito.
Se hai bisogno di aiuto su come aggiungere snippet al tuo sito, consulta questo tutorial.
/**
* Change the sublabels for the Password field.
*
* @link https://wpforms.com/developers/how-to-change-the-password-field-sublabels/
*/
function wpf_dev_password_field_properties( $properties, $field, $form_data ) {
// Change sublabel values on the primary password field
$properties[ 'inputs' ][ 'primary' ][ 'sublabel' ][ 'value' ] = __( 'Please enter a password that you will use to sign on to your account.', 'your-text-domain' );
// Change the sublabel values on the secondary password field
$properties[ 'inputs' ][ 'secondary' ][ 'sublabel' ][ 'value' ] = __( 'Please re-enter that password again just for confirmation.', 'your-text-domain' );
return $properties;
}
add_filter( 'wpforms_field_properties_password' , 'wpf_dev_password_field_properties', 10, 3 );

E questo è tutto ciò che ti serve per modificare le sottodescrizioni. Desideri accedere automaticamente agli utenti dopo che hanno completato il processo di registrazione? Dai un'occhiata al nostro tutorial su Come accedere automaticamente agli utenti dopo la registrazione.
Filtro di Riferimento
FAQ
D: Posso cambiarle solo per un modulo?
R: Assolutamente, se desideri cambiare queste sottodidascalie solo per un modulo specifico, usa invece questo snippet e ricorda di aggiornare l'ID del modulo 123 per corrispondere al tuo ID modulo. Se hai bisogno di aiuto per trovare il tuo ID modulo, consulta questa guida utile.
/**
* Change the sublabels for the Password field.
*
* @link https://wpforms.com/developers/how-to-change-the-password-field-sublabels/
*/
function wpf_dev_password_field_properties( $properties, $field, $form_data ) {
// Only process this snippet on the form ID 123
if ( absint( $form_data[ 'id' ] ) !== 123 ) {
return $properties;
}
// Change sublabel values on the primary password field
$properties[ 'inputs' ][ 'primary' ][ 'sublabel' ][ 'value' ] = __( 'Please enter a password that you will use to sign on to your account.', 'your-text-domain' );
// Change the sublabel values on the secondary password field
$properties[ 'inputs' ][ 'secondary' ][ 'sublabel' ][ 'value' ] = __( 'Please re-enter that password again just for confirmation.', 'your-text-domain' );
return $properties;
}
add_filter( 'wpforms_field_properties_password' , 'wpf_dev_password_field_properties', 10, 3 );
Come puoi vedere nello snippet, tutto ciò che dobbiamo fare è aggiungere il controllo per l'ID del modulo con if ( absint( $form_data[ 'id' ] ) !== 123 ) { return $properties; } , il resto dello snippet rimane esattamente lo stesso dell'esempio con tutti i moduli.