You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parse padding presets for use in sizes values #1240
As described in this comment. In order to make an image's sizes value more accurately reflect the constraints of its alignment container, we need to incorporate the way padding settings affect the width of the container. For example, in the Twenty Twenty-four theme, the default settings.layout.contentSizesetting is 620px, which is the max size that the container will be on larger viewport widths, but that width gets constrained by the padding styles for the site.
However, in many cases, theme.json padding styles reference the global padding settings, using CSS variables like var(--wp--preset--spacing--50), which cannot be calculated by the browser when the sizes attribute is parsed, so we will need a way to parse these settings into valid media query values.
For sure! But I intentionally don't want to make OD a dependency of this effort for now. I think OD could be used to enhance things but it would be good to have some improvements that could be merged to WP without also merging the whole OD API.
Instead of trying to parse the value of CSS variables in theme.json on the server, an alternate idea to explore here is to see if these values can be used by CSS functions if they are included in the initial page render from WordPress.
So for example, if core is including inline styles using the global-styles-inline-css handle that defines values like --wp--preset--spacing--30, etc. Could they be used directly in sizes values?
The wp_get_global_stylesheet function is responsible for retrieving the CSS, which we can parse to extract the necessary CSS values for use in the sizes attribute. This approach looks promising based on an initial review and is worth exploring further.
Activity
[-]Parse padding presets for use in sizes values[/-][+]Parse padding presets for use in `sizes` values[/+]swissspidy commentedon May 23, 2024
An alternative to parsing those values could be to use Optimization Detective, WDYT?
joemcgill commentedon May 24, 2024
For sure! But I intentionally don't want to make OD a dependency of this effort for now. I think OD could be used to enhance things but it would be good to have some improvements that could be merged to WP without also merging the whole OD API.
joemcgill commentedon Dec 18, 2024
Instead of trying to parse the value of CSS variables in theme.json on the server, an alternate idea to explore here is to see if these values can be used by CSS functions if they are included in the initial page render from WordPress.
So for example, if core is including inline styles using the
global-styles-inline-csshandle that defines values like--wp--preset--spacing--30, etc. Could they be used directly insizesvalues?mukeshpanchal27 commentedon Dec 19, 2024
The
wp_get_global_stylesheetfunction is responsible for retrieving the CSS, which we can parse to extract the necessary CSS values for use in thesizesattribute. This approach looks promising based on an initial review and is worth exploring further.