Your Site Icon in Place of the WordPress Logo in the Admin Bar
Replaces the WordPress logo menu in the admin bar with your Site Icon linking to the dashboard, a simple branding touch for client sites.
Opens WPIDE on
Code
add_action( 'admin_bar_menu', function ( $admin_bar ) {
$admin_bar->remove_node( 'wp-logo' );
$icon = get_site_icon_url( 32 );
$name = get_bloginfo( 'name' );
$mark = $icon
? '<img src="' . esc_url( $icon ) . '" alt="" width="20" height="20" style="width:20px;height:20px;border-radius:3px;vertical-align:middle;margin-top:-3px">'
: '<span style="display:inline-block;width:20px;height:20px;line-height:20px;text-align:center;border-radius:3px;background:#2271b1;color:#fff;font-weight:600">' . esc_html( strtoupper( mb_substr( $name, 0, 1 ) ) ) . '</span>';
$admin_bar->add_node( array(
'id' => 'wpide-site-logo',
'title' => $mark . '<span class="screen-reader-text">' . esc_html( $name ) . '</span>',
'href' => admin_url(),
) );
}, 11 );
Notes
Set a Site Icon under Settings > General first; without one the site name's first letter is shown.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.