Home » Functions » wp_nonce_field

WordPress provides many built-in security functions that help protect websites from malicious attacks. One such function is wp_nonce_field. In this article, we will explain what wp_nonce_field does, and how it can be used to improve the security of your WordPress website.

wp_nonce_field is a function that generates a unique nonce (number used once) token, which can be used to verify that a form submission is coming from an authorized source. The wp_nonce_field function generates both a hidden field with the nonce value and a referer field that contains the URL of the current page. This ensures that the form submission is only valid if it comes from the page on which the form appears.

The wp_nonce_field function takes two arguments: the first is a unique name for the nonce, and the second is a boolean value that indicates whether the nonce should be added as a URL parameter. If this value is set to true, the nonce will be added to the URL as a query string parameter.

Here’s an example usage code:

<?php wp_nonce_field( 'my_custom_action', 'my_custom_nonce' ); ?>

In this example, the wp_nonce_field function is generating a unique nonce with the name "my_custom_nonce" for the custom action "my_custom_action". This nonce can be used to verify that the form submission is coming from an authorized source.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.