Make WordPress Core


Ignore:
Timestamp:
07/01/2026 06:08:42 PM (3 months ago)
Author:
scruffian
Message:

Toolbar: Show the site icon in the admin bar when one is set.

When a site icon is configured, it is displayed in the WordPress admin bar in place of the home/odometer dashicon. The icon is shown at 20×20px with a border-radius of 2px. When no site icon is set, the existing dashicon behavior is preserved.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11781.

Props fushar, tyxla, joen, wildworks, scruffian, sergeybiryukov, lucasmdo, joedolson.
Fixes #65088. See #46657, #64308.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/admin-bar.php

    r62592 r62614  
    277277        $howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . wp_get_current_user()->display_name . '</span>' );
    278278
    279         $avatar = get_avatar( $user_id, 28 );
     279        $avatar = get_avatar( $user_id, 26 );
    280280        $wp_admin_bar->add_node(
    281281                array(
    … …  
    386386
    387387        $title = wp_html_excerpt( $blogname, 40, '&hellip;' );
     388        $meta  = array(
     389                'menu_title' => $title,
     390        );
     391
     392        if ( ! is_network_admin() && ! is_user_admin() ) {
     393                /** This filter is documented in wp-includes/admin-bar.php */
     394                $show_site_icons = apply_filters( 'wp_admin_bar_show_site_icons', true );
     395
     396                if ( true === $show_site_icons && has_site_icon() ) {
     397                        $site_icon = sprintf(
     398                                '<img class="site-icon" src="%s" srcset="%s 2x" alt="" width="20" height="20" />',
     399                                esc_url( get_site_icon_url( 32 ) ),
     400                                esc_url( get_site_icon_url( 64 ) )
     401                        );
     402
     403                        $title         = $site_icon . $title;
     404                        $meta['class'] = 'has-site-icon';
     405                }
     406        }
    388407
    389408        $wp_admin_bar->add_node(
    … …  
    392411                        'title' => $title,
    393412                        'href'  => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),
    394                         'meta'  => array(
    395                                 'menu_title' => $title,
    396                         ),
     413                        'meta'  => $meta,
    397414                )
    398415        );
Note: See TracChangeset for help on using the changeset viewer.