wordpress use nonce in form

 Use the following code inside just before tag on your front end code.

wp_nonce_field('name_of_your_action', 'name_of_your_nonce_field');

The above code will generate two hidden inputs inside your form tag. Now you can verify your nonce in the backend where you will process your form. Use the following code to verify the nonce you just created above.

  if(wp_verify_nonce($_REQUEST['name_of_your_nonce_field'], 'name_of_your_action')){

// Nonce is matched and valid. do whatever you want now.

} else {

// Invalid nonce. you can throw an error here.
}


refer - https://wp-kama.com/function/wp_nonce_field
https://developer.wordpress.org/themes/theme-security/using-nonces/

Leave a Comment

Your email address will not be published. Required fields are marked *