{"id":89953,"date":"2012-07-28T11:00:02","date_gmt":"2012-07-28T15:00:02","guid":{"rendered":"http:\/\/wpmu.org\/?p=89953"},"modified":"2012-07-27T23:40:59","modified_gmt":"2012-07-28T03:40:59","slug":"wordpress-delete-button-admin-bar","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/wordpress-delete-button-admin-bar\/","title":{"rendered":"How to Add a Delete Button to the WordPress Admin Bar"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-89956\" title=\"delete-big\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/delete-big.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"689\" height=\"580\" \/>I came across this nice little piece of code recently <a href=\"http:\/\/wpengineer.com\/2185\/add-trash-button-to-wordpress-admin-bar\/\" rel=\"noopener\" target=\"_blank\">at wpengineer.com<\/a>. It <strong>adds a Delete button to your WordPress Admin Bar<\/strong> when you\u2019re on a single post page. This lets you<strong> easily delete a post from your front end<\/strong> \u2013 very handy for some sites that end up doing a lot of deleting for one reason or another.<\/p>\n<p>To use this, enter the following code into your functions.php file. \u00a0<strong>(Appearance &gt; Edit &gt; Theme Functions \u2013 functions.php)<\/strong><\/p>\n<pre>function fb_add_admin_bar_trash_menu() {\r\nglobal $wp_admin_bar;\r\nif ( !is_super_admin() || !is_admin_bar_showing() )\r\nreturn;\r\n$current_object = get_queried_object();\r\nif ( empty($current_object) )\r\nreturn;\r\nif ( !empty( $current_object-&gt;post_type ) &amp;&amp;\r\n( $post_type_object = get_post_type_object( $current_object-&gt;post_type ) ) &amp;&amp;\r\ncurrent_user_can( $post_type_object-&gt;cap-&gt;edit_post, $current_object-&gt;ID )\r\n) {\r\n$wp_admin_bar-&gt;add_menu(\r\narray( 'id' =&gt; 'delete',\r\n'title' =&gt; __('Move to Trash'),\r\n'href' =&gt; get_delete_post_link($current_object-&gt;term_id)\r\n)\r\n);\r\n}\r\n}\r\nadd_action( 'admin_bar_menu', 'fb_add_admin_bar_trash_menu', 35 );<\/pre>\n<p>And here&#8217;s what it looks like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-89957\" title=\"add-delete-button-to-admin-bar\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/add-delete-button-to-admin-bar.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"689\" height=\"580\" \/><\/p>\n<p>Note: Technically the code above adds a button that says, \u201cMove to Trash.\u201d If you\u2019d like to change it to say something else like \u201cDelete,\u201d then just change the text inside of the single quotation marks in this section:<\/p>\n<pre>'title' =&gt; __('Move to Trash'),<\/pre>\n<p>For example, change it to \u2026<\/p>\n<pre>'title' =&gt; __('Delete\u2019),<\/pre>\n<p>If you&#8217;d like to put a Delete link in the post area itself, check out this post &#8211; <a href=\"https:\/\/wpmudev.com\/blog\/how-to-add-a-delete-post-link-to-your-wordpress-posts\/\" target=\"_blank\"><em>How to Add a Delete Post Link to Your WordPress Posts<\/em><\/a>.<\/p>\n\n<p>Photo: <a href=\"http:\/\/www.bigstockphoto.com\/image-14364014\/stock-vector-delete-sticker-icon-vector-illustration\" target=\"_blank\">Delete sticker icon<\/a> from BigStock<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This neat little trick puts a \u201cMove to Trash\u201d button on your Admin Bar.<\/p>\n","protected":false},"author":84404,"featured_media":89955,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[8822],"tutorials_categories":[],"class_list":["post-89953","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-toolbar"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/89953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=89953"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/89953\/revisions"}],"predecessor-version":[{"id":216684,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/89953\/revisions\/216684"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/89955"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=89953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=89953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=89953"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=89953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}