From f5991aed63e0a22d312e237982b3d2e715059532 Mon Sep 17 00:00:00 2001 From: johnjamesjacoby Date: Tue, 2 Nov 2021 17:21:58 +0000 Subject: [PATCH] Themes: Introduce `get_header_image_tag_attributes` hook. This change adds a filter inside of the `get_header_image_tag()` function allowing developers to filter the attributes of the header image HTML tag before they are escaped, concatenated, and returned. Before this change, it was not possible to externally and preemptively intercept this array of attributes. After this change, these attributes can now be easily filtered, matching it nicely to the `wp_get_attachment_image_attributes` hook. Props audrasjb, chaion07, junaidbhura, sabernhardt. Fixes #38942. Built from https://develop.svn.wordpress.org/trunk@51978 git-svn-id: http://core.svn.wordpress.org/trunk@51567 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/theme.php | 10 ++++++++++ wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index e233b4127a..86db220d78 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1234,6 +1234,16 @@ function get_header_image_tag( $attr = array() ) { } } + /* + * Filters the list of header image attributes. + * + * @since 5.9.0 + * + * @param array $attr Array of the attributes for the image tag. + * @param object $header The custom header object returned by 'get_custom_header()'. + */ + $attr = apply_filters( 'get_header_image_tag_attributes', $attr, $header ); + $attr = array_map( 'esc_attr', $attr ); $html = '