Delete Post Link
August 25th, 2008In 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', '<p>', '</p>')
To get all new functions/template tags, install my plugin WP Extra Template Tags.
Thanks. Very helpful.
I would like to get a confirmation, now it deletes the post immediately, that sux.
Can you implement this?
This is very useful and hard to find lol! You should make it a plugin so it can get some recognition
Thanks!
Is it possible to get a confirmation before deleting?
thanks man. I’ll translate it on Russian