Add a “Delete Post” Link to your WordPress Posts!

Add a simple delete link right on your website that is running WordPress. Tested with WordPress version 5.1.

Since the PHP code is written by me it looks like crap, but it doesn’t really matter since the admin is the only one who will see it.

Add this code inside the WordPress loop and reload your website.
If you have logged in as Admin you should see a “[Delete Post]” link somewhere.

When you click it a dialog will pop up, asking you to confirm to delete the post.
I didn’t want the page to reload every time I did delete stuff, that’s why the small iframe is added. It will simply load the delete link inside it. (Told you it was crap code, but it works.)

WordPress Code:
<?php if ( is_super_admin() ) { ?>
<p><a onclick="return confirm('Do you want to delete this post?')" href="<?php echo get_delete_post_link( $post->ID ) ?>" target="deleteframe">[Delete Post]</a></p><iframe name="deleteframe" width="200px" height="35px"><a href="https://www.nordicnode.com/">NordicNode</a></iframe>
<?php } ?>

That’s it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.