This basic tutorial will help you with add simple Edit, Trash and Delete links on the front-end of your WordPress theme for administrative users to moderate the posts in a multi-user setup or in sections where WordPress doesn’t automatically show ‘Edit Post‘ link on the administration bar. The code will enable Administrators to edit, trash and delete posts from sections like author and date archives with single clicks.
Here’s the exact code I’ve been using on my WordPress installations. The functions are well explained in the WordPress Codex pages should you need more details about the functions and attributes you can use.
<?php edit_post_link(‘ | Edit’, ”, ‘ | ‘); ?>
echo “<a href='” . get_delete_post_link(null, ”) . “‘ target=’_blank’/>Trash |</a>” .
“<a href='” . get_delete_post_link(null, ”, true) . “‘ target=’_blank’/> Delete</a>”;
What the above code does is, the edit_post_link() function generates a Edit post link with the separator ‘|’. The current_user_can() function checks if the registered user has permissions to delete posts before the links are shown to the user. The get_delete_post_link() function generates a valid delete post link from WordPress to trash the post to the WordPress vault without deleting it permanently. And lastly the get_delete_post_link() with the ‘true‘ attribute at the end calls for post to be deleted permanently from the WordPress. The permanent deleted posts are irreversible so do not mistakenly click them.
That’s just about it. Add it to a section of the theme where you want them to appear. The recommended places would be archives and index pages where multiple posts appear. And do let us know if you have any comments, suggestion or what you think about this in the comments.