get_delete_post_link

Home » Functions » get_delete_post_link

Function Name: get_delete_post_link

The get_delete_post_link WordPress function is used to generate a link that will send a request to delete a specified post. The function returns HTML markup which can be used to display a link or button which, when clicked, will delete the post.

This function takes two arguments. The first argument is the post ID of the post that should be deleted. The second argument is the URL which should be used as the destination after the post has been deleted.

It’s important to note that this function only generates a link to delete the post. It doesn’t actually perform the deletion. A confirmation prompt will be displayed when the link is clicked, giving the user the option to confirm or cancel the deletion.

Here is an example usage code for the get_delete_post_link function:

<?php
$delete_link = get_delete_post_link( $post_id, $redirect_url );
echo '<a href="' . esc_url( $delete_link ) . '">Delete Post</a>';
?>

In this example, the $post_id variable represents the ID of the post that should be deleted, and the $redirect_url variable represents the URL which should be used as the destination after the post has been deleted. The generated link is then output as HTML markup using the echo statement.

Learn More on WordPress.org

WordPress snippets using the get_delete_post_link function

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