delete_post_link()
2010-01-16 @ 14:55In most WordPress themes, if you are logged in, there is an ”Edit Post” link. That way you can go directly into edit the current post.
I have created a function called ”Delete Post Link”. If you are logged in you will see a link which allows you to delete the current page or post, even without visiting admin.
Warning! You should be very careful using this function!
function wp_delete_post_link($link = 'Delete This', $before = '', $after = '')
{
global $post;
if ( $post->post_type == 'page' ) {
if ( !current_user_can( 'edit_page', $post->ID ) )
return;
} else {
if ( !current_user_can( 'edit_post', $post->ID ) )
return;
}
$link = "<a href='" . wp_nonce_url( get_bloginfo('url') . "/wp-admin/post.php?action=delete&post=" . $post->ID, 'delete-post_' . $post->ID) . "'>".$link."</a>";
echo $before . $link . $after;
}
I recommend you to put the function into your functions.php file in your theme folder. When done just put the function into your theme like this:
wp_delete_post_link('Delete this post / page', '<p>', '</p>')





