_ap_ufes{"success":true,"siteUrl":"www.jucktion.com/tech","urls":{"Home":"https://www.jucktion.com/tech","Category":"https://www.jucktion.com/tech/c/mobile/android/","Archive":"https://www.jucktion.com/tech/2018/01/","Post":"https://www.jucktion.com/tech/incoming-remote-desktop-windows-home/","Page":"https://www.jucktion.com/tech/about/","Attachment":"https://www.jucktion.com/tech/incoming-remote-desktop-windows-home/windows-10-home-rdp-setup/","Nav_menu_item":"https://www.jucktion.com/tech/3985/"}}_ap_ufee Add Edit/Trash/Delete link on the front-end of WordPress - Tech Junction

Add Edit/Trash/Delete link on the front-end of WordPress

By | 5th January, 2015 | 0 Comments

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.

Wordpress edit delete trash posts

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’, ”, ‘ | ‘); ?>
<?php if(current_user_can(‘delete_posts’)){
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.

Tags: , , ,

Category: WordPress