WordPress get_delete_post_link() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Returns a URL

Definition

In WordPress, get_delete_post_link() returns a URL that moves a post to the Trash. With one option it can delete the post for good.

The URL has a security code (a nonce), so it cannot be guessed. If the current user is not allowed to delete the post, the function returns nothing. Always check the result before you print a link.

Syntax

Get the URL, check it, then print a link.

WordPress
<?php $url = get_delete_post_link(); ?>
CallWhat it does
get_delete_post_link()Trash link for the current post.
get_delete_post_link( 42 )Trash link for post 42.
get_delete_post_link( 42, '', true )Link that deletes post 42 permanently.

It returns a URL. It does not delete anything by itself. The post is only removed when someone opens the link.

Full declaration
WordPress
get_delete_post_link( int|WP_Post $post = 0, string $deprecated = '', bool $force_delete = false ): string|void

Parameters

ParameterDescription
$postint|WP_Post. The post ID or object. Default is 0, which means the current post.
$deprecatedstring. Not used anymore. Pass an empty string.
$force_deletebool. If true, the link deletes the post permanently. If false (default), it moves the post to the Trash.

Return Value

Return ValueDescription
stringThe delete URL, with a nonce.
nothing (void)If the post does not exist or the user cannot delete it.

WordPress Examples

Three short examples. Each one shows the code and what it prints or does.

Example 1 — Get the trash URL

Print the URL of the current post for an admin.

WordPress
<?php
$url = get_delete_post_link();
if ( $url ) {
  echo esc_url( $url );
}

How It Works

  1. get_delete_post_link() builds a trash URL for the current post.
  2. The check makes sure there is a URL (visitors get nothing).
  3. The _wpnonce part is the security code.

Example 2 — Delete permanently with force_delete

Set the third argument to true to skip the Trash.

WordPress
<?php
$url = get_delete_post_link( 42, '', true );
if ( $url ) {
  echo esc_url( $url );
}

How It Works

  1. 42 is the post ID.
  2. The empty string is the unused second argument.
  3. true changes the action from trash to delete.

Frequently Asked Questions

It returns a secure URL that moves a post to the Trash, or deletes it permanently if you ask for that.
No. It only builds the URL. The post is removed when someone opens the link.
The post may not exist, or the current user may not have permission to delete it.
It is a one-time security code. It protects the link from being used by someone else.
Pass true as the third argument. Use it carefully, because the post cannot be restored.

Next: get_edit_post_link()

Return the admin URL for editing a post, or null if the user cannot edit it.

get_edit_post_link() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful