get_delete_post_link()
Retrieves the delete posts link for post.
Can be used within the WordPress loop or outside of it, with any post type.
Hooks from the function
Return
String|null
. The delete post link URL for the given post.
Usage
get_delete_post_link( $post, $deprecated, $force_delete );
- $post(int|WP_Post)
- Post ID or post object.
Default: global $post - $deprecated(string)
- Not used.
Default: '' - $force_delete(true|false)
- Whether to bypass Trash and force deletion.
Default: false
Examples
#1 Demo Sample
echo get_delete_post_link( 1 ); // http://example.com/wp-admin/post.php?post=1&action=delete&_wpnonce=d21da8cad3
#2 Full link to delete the post:
echo '<a href="'. get_delete_post_link() .'">delete post</a>';
#3 Display the link only if the user has enough privilege for deletion:
if( current_user_can( 'delete_posts' ) ) { echo '<a href="'. get_delete_post_link( $post->ID) .'">Delete without restoring</a>'; }
Changelog
Since 2.9.0 | Introduced. |