Att ta ett snabblån kan ibland vara räddningen på en jobbig sists. Hos Snabblån 24 har du en perfekt överblick över alla lån-företag och vad de erbjuder. Det gör att du kan välja lånet som passar dig bäst.

Delete Post Link

August 25th, 2008

In 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 ) )
	} else {
		if ( !current_user_can( 'edit_post', $post->ID ) )
	$link = "<a href='" . wp_nonce_url( get_bloginfo('url') . "/wp-admin/post.php?action=delete&amp;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.

  1. 2010-09-13 - Dan

    Exactly what I needed for one of my projects, saved me some time making it from scratch. Thanks a lot, works very smooth in BuddyPress.

  2. 2010-07-17 - Austin

    When I use this in my wp admin I get this error message and the post is not deleted:
    Are you sure you want to do this? Please try again.

    What am I doing wrong? I think it has something to do with wp_nonce_url…

  3. 2010-01-26 - Jordan

    Thanks. Very helpful.

  4. 2009-12-10 - peter

    I would like to get a confirmation, now it deletes the post immediately, that sux.

    Can you implement this?

  5. 2009-11-17 - baseball2525

    This is very useful and hard to find lol! You should make it a plugin so it can get some recognition :D Thanks!

  6. 2009-11-10 - manaa

    Is it possible to get a confirmation before deleting?

  7. 2009-06-03 - Admi

    thanks man. I’ll translate it on Russian

  1. » How to Add a Delete Post Link to Your WordPress Posts
    How to Add a Delete Post Link to Your WordPress Posts | SNS Online
    How to Add a Delete Post Link to Your WordPress Posts
    Delete Link For Wordpress Blog
    Progress 16/06/2010 « Tara Jane Irvine
    Kaip palengvinti asmeninio wiki tvarkymą wordpresse « kurapka
    » Delete Post Link