I need both Admin and Editor role users to be able to delete a custom post type from the front-end. I found the code to create a post delete link, but whenever either role tries to delete there is an error:

Forbidden You don't have permission to access /wp-admin/post.php on this server.

Any ideas? Is it because this is a custom post type? The post delete code is included below.

In function.php:

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 onclick=\"return confirm('Are you SURE you want to delete this post/page?')\" 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;

Inserted into page:

<?php wp_delete_post_link('Delete', ' <strong class="delete">', '</strong> ') ?>
  • That looks like a server error outside of WordPress - are you sure the URL is valid & points to the correct location of wp-admin/post.php? Commented Jan 11, 2012 at 19:21

1 Answer 1


Here you go, this creates a Delete Post link that only appears to the user if they are both logged in and the author of the post. When the link is clicked, they get a js confirmation asking them if they're sure, which once clicked will delete the post. And it does work with Custom Post Types, tested it myself.

<?php if ($post->post_author == $current_user->ID) { ?><p><a onclick="return confirm('Are you SURE you want to delete this post?')" href="<?php echo get_delete_post_link( $post->ID ) ?>">Delete post</a></p><?php } ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.