Make WordPress Core

Changeset 53100


Ignore:
Timestamp:
04/07/2022 10:12:34 PM (23 months ago)
Author:
audrasjb
Message:

Toolbar: Add a filter to help remove site icons from toolbar for large multisite, and lazy load them by default.

This changeset introduces the wp_admin_bar_show_site_icons filter to help developers to hide site icons from the toolbar, as it may have negative performance impact on large multisites. It also adds a default lazy load behavior for these icons.

Props wslyhbb, sabernhardt, lkraav, kebbet, peterwilsoncc.
Fixes #54447

File:
1 edited

Legend:

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

    r53060 r53100  
    612612    );
    613613
     614    /**
     615     * Filters whether to show the site icons in toolbar.
     616     *
     617     * Returning false to this hook is the recommended way to hide site icons in the toolbar.
     618     * A truthy return may have negative performance impact on large multisites.
     619     *
     620     * @since 6.0.0
     621     *
     622     * @param bool $show_site_icons Whether site icons should be shown in the toolbar. Default true.
     623     */
     624    $show_site_icons = apply_filters( 'wp_admin_bar_show_site_icons', true );
     625
    614626    foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
    615627        switch_to_blog( $blog->userblog_id );
    616628
    617         if ( has_site_icon() ) {
     629        if ( true === $show_site_icons && has_site_icon() ) {
    618630            $blavatar = sprintf(
    619                 '<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16" />',
     631                '<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16"%s />',
    620632                esc_url( get_site_icon_url( 16 ) ),
    621                 esc_url( get_site_icon_url( 32 ) )
     633                esc_url( get_site_icon_url( 32 ) ),
     634                ( wp_lazy_loading_enabled( 'img', 'site_icon_in_toolbar' ) ? ' loading="lazy"' : '' )
    622635            );
    623636        } else {
Note: See TracChangeset for help on using the changeset viewer.