Title: wp_nonce_ays
Published: April 25, 2014
Last modified: May 20, 2026

---

# wp_nonce_ays( string $action )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#wp--skip-link--target)

Displays “Are You Sure” message to confirm the action being taken.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#description)󠁿

If the action has the nonce explain message, then it will be displayed along with
the “Are you sure?” message.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#parameters)󠁿

 `$action`stringrequired

The nonce action.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#source)󠁿

    ```php
    function wp_nonce_ays( $action ) {
    	// Default title and response code.
    	$title         = __( 'An error occurred.' );
    	$response_code = 403;

    	if ( 'log-out' === $action ) {
    		$title = sprintf(
    			/* translators: %s: Site title. */
    			__( 'You are attempting to log out of %s' ),
    			get_bloginfo( 'name' )
    		);

    		$redirect_to = $_REQUEST['redirect_to'] ?? '';

    		$html  = $title;
    		$html .= '</p><p>';
    		$html .= sprintf(
    			/* translators: %s: Logout URL. */
    			__( 'Do you really want to <a href="%s">log out</a>?' ),
    			wp_logout_url( $redirect_to )
    		);
    	} else {
    		$html = __( 'The link you followed has expired.' );

    		if ( wp_get_referer() ) {
    			$wp_http_referer = remove_query_arg( 'updated', wp_get_referer() );
    			$wp_http_referer = wp_validate_redirect( sanitize_url( $wp_http_referer ) );

    			$html .= '</p><p>';
    			$html .= sprintf(
    				'<a href="%s">%s</a>',
    				esc_url( $wp_http_referer ),
    				__( 'Please try again.' )
    			);
    		}
    	}

    	wp_die( $html, $title, $response_code );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/functions.php#L3690)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/functions.php#L3690-L3728)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_validate_redirect()](https://developer.wordpress.org/reference/functions/wp_validate_redirect/)`wp-includes/pluggable.php` |

Validates a URL for use in a redirect.

  | 
| [wp_logout_url()](https://developer.wordpress.org/reference/functions/wp_logout_url/)`wp-includes/general-template.php` |

Retrieves the logout URL.

  | 
| [wp_get_referer()](https://developer.wordpress.org/reference/functions/wp_get_referer/)`wp-includes/functions.php` |

Retrieves referer from ‘_wp_http_referer’ or HTTP referer.

  | 
| [remove_query_arg()](https://developer.wordpress.org/reference/functions/remove_query_arg/)`wp-includes/functions.php` |

Removes an item or items from a query string.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  | 
| [get_bloginfo()](https://developer.wordpress.org/reference/functions/get_bloginfo/)`wp-includes/general-template.php` |

Retrieves information about the current site.

  | 
| [sanitize_url()](https://developer.wordpress.org/reference/functions/sanitize_url/)`wp-includes/formatting.php` |

Sanitizes a URL for database or redirect usage.

  | 
| [wp_die()](https://developer.wordpress.org/reference/functions/wp_die/)`wp-includes/functions.php` |

Kills WordPress execution and displays HTML page with an error message.

  |

[Show 5 more](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#)

| Used by | Description | 
| [check_admin_referer()](https://developer.wordpress.org/reference/functions/check_admin_referer/)`wp-includes/pluggable.php` |

Ensures intent by verifying that a user was referred from another admin page with the correct security nonce.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.4](https://developer.wordpress.org/reference/since/2.0.4/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_nonce_ays/?output_format=md#comment-content-6379)
 2.   [Alvaro Torres](https://profiles.wordpress.org/algato333/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/wp_nonce_ays/#comment-6379)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_nonce_ays%2F%23comment-6379)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_nonce_ays%2F%23comment-6379)
 4. We can use it to log-out by using log-out as argument: `wp_nonce_ays('log-out');`
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_nonce_ays%2F%3Freplytocom%3D6379%23feedback-editor-6379)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_nonce_ays%2F)
before being able to contribute a note or feedback.