Make WordPress Core

Changeset 52256


Ignore:
Timestamp:
11/26/2021 10:54:10 PM (3 years ago)
Author:
audrasjb
Message:

Media: Allow setting custom image alt text in custom header image.

This change applies the alternative text assigned to the custom header image, if available. Otherwise, it leaves it empty. It fixes an issue where the alternative text was always the site title, which is not relevant in most use cases.

Props webmandesign, mukesh27, afercia, anevins, mikeschroder, nrqsnchz, audrasjb, sabernhardt, joedolson, Boniu91.
Fixes #46124.

File:
1 edited

Legend:

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

    r52247 r52256  
    11951195    $height = absint( $header->height );
    11961196
     1197    // Use alternative text assigned to the image, if available. Otherwise, leave it empty.
     1198    if ( ! empty( $header->attachment_id ) && is_string( get_post_meta( $header->attachment_id, '_wp_attachment_image_alt', true ) ) ) {
     1199        $alt = get_post_meta( $header->attachment_id, '_wp_attachment_image_alt', true );
     1200    } else {
     1201        $alt = '';
     1202    }
     1203
    11971204    $attr = wp_parse_args(
    11981205        $attr,
     
    12011208            'width'  => $width,
    12021209            'height' => $height,
    1203             'alt'    => get_bloginfo( 'name' ),
     1210            'alt'    => $alt,
    12041211        )
    12051212    );
Note: See TracChangeset for help on using the changeset viewer.