Add Some Fancy to the Edit Page/Post Link

Inspired by this tweet.

Add a little bit of fancy to your edit link in the Admin Bar with this:

add_action( 'wp_before_admin_bar_render', 'adminbar_tweaks');

function adminbar_tweaks() {
    global $wp_admin_bar;

    if (isset( $wp_admin_bar->menu->edit['title'] ) ) {
        $title = $wp_admin_bar->menu->edit['title'];
        if ( substr( $title, 0, 5 ) == 'Edit ' ) {
            $hand = '<span style="font-size:20px;margin:-1px 3px 0 0;float:left;">✍</span>';
            $wp_admin_bar->menu->edit['title'] = $hand.$title;
        }
    }

}

Sort “My Sites” Menu Alphabetically

If you have a WordPress Network and you use the My Sites menu a lot, you might wish the list was sorted alphabetically, rather than by site ID.

Here’s how you can reorder that list

Method 1: Modify the Admin Bar/Toolbar directly

add_action('admin_bar_menu', 'reorder_my_sites');
function reorder_my_sites( $wp_admin_bar ) {

    //get "my sites"
    $mysites = $wp_admin_bar->user->{'blogs'};
    //and remove the unsorted list
    unset( $wp_admin_bar->user->{'blogs'} );

    //loop thru mysites to get id and title
    $pairs = array();
    foreach($mysites as $id => $info) {
        $pairs[$id] = strip_tags($info->blogname);
    }
    $pairs = array_map( 'strtoupper', $pairs );
    //sort by title, keep id
    asort($pairs);

    //loop thru sorted sites, and put back in menu
    foreach ($pairs as $id => $title) {
        $wp_admin_bar->user->{'blogs'}->$id = $mysites[$id];
    }
}

Method 2: Reorder the user’s blogs, before the menu is rendered

add_filter('get_blogs_of_user','reorder_users_sites');
function reorder_users_sites( $blogs ) {
	$f = create_function('$a,$b','return strcasecmp($a->blogname, $b->blogname);');
	uasort( $blogs, $f );
	return $blogs;
}

Method 2 credit

 

Add Links to the Admin Bar

It can be really useful to add some custom links to the Admin Bar. Like, perhaps to the hidden-yet-awesome options.php page.

add_action( 'admin_bar_menu', 'additional_admin_bar_menu', 70 );
function additional_admin_bar_menu( $wp_admin_bar ) {
    if ( current_user_can('manage_options') )
    $wp_admin_bar->add_menu( array( 'id' => 'all-settings', 'title' => __('All Settings'), 'href' => admin_url('options.php') ) );
}

If you want to add a sub-menu item, you must add a “parent” parameter, and its value should match the ID of the parent element.

add_action( 'admin_bar_menu', 'additional_admin_bar_menu_child', 70 );
function additional_admin_bar_menu_child( $wp_admin_bar ) {
        $wp_admin_bar->add_menu( array( 'parent' => 'all-settings', 'id' => 'google', 'title' => __('Google'), 'href' => 'http://google.com' ) );
}