-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Print IMG
auto-sizes contain CSS fix by enqueueing inline style
#8954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
c99d5fd
e7144a3
41d68bf
5540458
92c5985
631feac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2061,25 +2061,29 @@ function wp_sizes_attribute_includes_valid_auto( string $sizes_attr ): bool { | |||||
} | ||||||
|
||||||
/** | ||||||
* Prints a CSS rule to fix potential visual issues with images using `sizes=auto`. | ||||||
* Enqueues a CSS rule to fix potential visual issues with images using `sizes=auto`. | ||||||
* | ||||||
* This rule overrides the similar rule in the default user agent stylesheet, to avoid images that use e.g. | ||||||
* `width: auto` or `width: fit-content` to appear smaller. | ||||||
* | ||||||
* @since 6.7.1 | ||||||
* @since 6.9.0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be 6.8.2 if we want.
Suggested change
|
||||||
* | ||||||
* @see https://html.spec.whatwg.org/multipage/rendering.html#img-contain-size | ||||||
* @see https://core.trac.wordpress.org/ticket/62413 | ||||||
*/ | ||||||
function wp_print_auto_sizes_contain_css_fix() { | ||||||
function wp_enqueue_img_auto_sizes_contain_css_fix(): void { | ||||||
/** This filter is documented in wp-includes/media.php */ | ||||||
$add_auto_sizes = apply_filters( 'wp_img_tag_add_auto_sizes', true ); | ||||||
if ( ! $add_auto_sizes ) { | ||||||
return; | ||||||
} | ||||||
|
||||||
?> | ||||||
<style>img:is([sizes="auto" i], [sizes^="auto," i]) { contain-intrinsic-size: 3000px 1500px }</style> | ||||||
<?php | ||||||
$handle = 'wp-img-auto-sizes-contain'; | ||||||
wp_register_style( $handle, false ); | ||||||
wp_add_inline_style( $handle, 'img:is([sizes="auto" i], [sizes^="auto," i]) { contain-intrinsic-size: 3000px 1500px }' ); | ||||||
|
||||||
// Make sure inline style is printed first since it was previously printed at wp_head priority 1 and this preserves the CSS cascade. | ||||||
array_unshift( wp_styles()->queue, $handle ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a bit hacky to me, but I understand the purpose. I assume there's not a better way to control the order of registered styles besides maybe making sure that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. |
||||||
} | ||||||
|
||||||
/** | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per below, if we want to target the next minor release: