Make WordPress Core


Ignore:
Timestamp:
09/14/2023 11:23:59 AM (7 months ago)
Author:
spacedmonkey
Message:

Bundled Theme: Implement the_header_image_tag function for enhanced compatibility for older core themes.

The the_header_image_tag function was introduced in WordPress 4.4 as part of [35594]. It is used in all themes created post WordPress 4.4 that supported header images. The function get_header_image_tag continues to get updated with new image features, like lazy loading, async decoding and fetch priority. To ensure our core themes maintain compatibility and benefit from these enhancements, a backward compatibility shim has been applied, integrating the the_header_image_tag function into the following core themes:

  • Twenty Ten
  • Twenty Eleven
  • Twenty Twelve
  • Twenty Fourteen
  • Twenty Sixteen

This change ensures future compatibility and modern image features are applied for header images to these older themes.

Props spacedmonkey, flixos90, mukesh27.
Fixes #58675.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyten/functions.php

    r56315 r56583  
    291291endif;
    292292
     293
     294if ( ! function_exists( 'twentyten_header_image' ) ) :
     295    /**
     296     * Custom header image markup displayed.
     297     *
     298     * @since Twenty Ten 4.0
     299     */
     300    function twentyten_header_image() {
     301        $attrs = array(
     302            'alt' => get_bloginfo( 'name', 'display' ),
     303        );
     304
     305        // Compatibility with versions of WordPress prior to 3.4.
     306        if ( function_exists( 'get_custom_header' ) ) {
     307            $custom_header   = get_custom_header();
     308            $attrs['width']  = $custom_header->width;
     309            $attrs['height'] = $custom_header->height;
     310        } else {
     311            $attrs['width']  = HEADER_IMAGE_WIDTH;
     312            $attrs['height'] = HEADER_IMAGE_HEIGHT;
     313        }
     314
     315        if ( function_exists( 'the_header_image_tag' ) ) {
     316            the_header_image_tag( $attrs );
     317            return;
     318        }
     319
     320        ?>
     321        <img src="<?php header_image(); ?>" width="<?php echo esc_attr( $attrs['width'] ); ?>" height="<?php echo esc_attr( $attrs['height'] ); ?>" alt="<?php echo esc_attr( $attrs['alt'] ); ?>" />
     322        <?php
     323    }
     324endif; // twentyten_header_image()
     325
    293326/**
    294327 * Show a home link for our wp_nav_menu() fallback, wp_page_menu().
Note: See TracChangeset for help on using the changeset viewer.