Home | Articles | Wordpress | Add Move to Trash Button on WordPress Admin Bar

Add Move to Trash Button on WordPress Admin Bar

If you are frequently making changes to your WordPress blog, you have have become tired of having to go through a bunch of menus to delete an out of date or irrelevant post. With a simple edit to your functions.php file, you can add a “Move to Trash” button to your WordPress Admin bar for simple deletes.

Open your functions.php file and add the following code:

<br />
// --------------------------------------------------------------------------<br />
// Start Add Delete Button to Admin Bar<br />
// --------------------------------------------------------------------------<br />
function fb_add_admin_bar_trash_menu() {<br />
  global $wp_admin_bar;<br />
  if ( !is_super_admin() || !is_admin_bar_showing() )<br />
      return;<br />
  $current_object = get_queried_object();<br />
  if ( empty($current_object) )<br />
      return;<br />
  if ( !empty( $current_object->post_type ) &&<br />
     ( $post_type_object = get_post_type_object( $current_object->post_type ) ) &&<br />
     current_user_can( $post_type_object->cap->edit_post, $current_object->ID )<br />
  ) {<br />
    $wp_admin_bar->add_menu(<br />
        array( 'id' => 'delete',<br />
            'title' => __('Move to Trash'),<br />
            'href' => get_delete_post_link($current_object->term_id)<br />
        )<br />
    );<br />
  }<br />
}<br />
add_action( 'admin_bar_menu', 'fb_add_admin_bar_trash_menu', 35 );<br />
// --------------------------------------------------------------------------<br />
// End Add Delete Button to Admin Bar<br />
// --------------------------------------------------------------------------<br />

Note: Some of these functions are not of my own creation, simply things I have found along the way. If you are the author of this function, please let me know so I can properly credit you with your work!

About Joe D

I have always had a passion for everything computing. In early 2000, I decided to take my passion to the web. Thus, C.O.D. was born. Through the years we have made many great friends at C.O.D. and hope to continue our journey for years to come.

Check Also

Manage Multiple WordPress Sites with InfiniteWP

Running your website, or websites, on WordPress is an easy choice as the flexibility the …

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.