Job2 Street

Friday, September 14, 2018

Here is a cool hack to add a “delete” button to 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:
01<br />
02// --------------------------------------------------------------------------<br />
03// Start Add Delete Button to Admin Bar<br />
04// --------------------------------------------------------------------------<br />
05function fb_add_admin_bar_trash_menu() {<br />
06  global $wp_admin_bar;<br />
07  if ( !is_super_admin() || !is_admin_bar_showing() )<br />
08      return;<br />
09  $current_object = get_queried_object();<br />
10  if ( empty($current_object) )<br />
11      return;<br />
12  if ( !empty( $current_object->post_type ) &&<br />
13     ( $post_type_object = get_post_type_object( $current_object->post_type ) ) &&<br />
14     current_user_can( $post_type_object->cap->edit_post, $current_object->ID )<br />
15  ) {<br />
16    $wp_admin_bar->add_menu(<br />
17        array( 'id' => 'delete',<br />
18            'title' => __('Move to Trash'),<br />
19            'href' => get_delete_post_link($current_object->term_id)<br />
20        )<br />
21    );<br />
22  }<br />
23}<br />
24add_action( 'admin_bar_menu', 'fb_add_admin_bar_trash_menu', 35 );<br />
25// --------------------------------------------------------------------------<br />
26// End Add Delete Button to Admin Bar<br />
27// --------------------------------------------------------------------------<br />
Note: Some of these functions are not of my own creation, simply things I have found along the w
The admin bar is a featured introduced by WordPress 3.1. It adds useful options such as adding new posts or editing an existing one. But it do not feature a “delete” button, so you can’t trash a post without accessing the post lists on the dashboard.
Here is a cool hack to add a “delete” button to WordPress admin bar.
Thanks to WP Engineer for great hack.

No comments:

Post a Comment

K-Play

kPlaylist - get your music online

The player will show in this paragraph

2 3

IkimFM

speaker music speaker