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
feat: first pass at enforcing image dimensions (#867)
<!--
Filling out this template is required. Any PR that does not include
enough information to be reviewed may be closed at a maintainers'
discretion. All new code requires documentation and tests to ensure
against regressions.
-->
### Description of the Change
<!--
We must be able to understand the design of your change from this
description. The maintainer reviewing this PR may not have worked with
this code recently, so please provide as much detail as possible.
Where possible, please also include:
- verification steps to ensure your change has the desired effects and
has not introduced any regressions
- any benefits that will be realized
- any alternative implementations or possible drawbacks that you
considered
- screenshots or screencasts
-->
<!-- Enter any applicable Issue number(s) here that will be
closed/resolved by this PR. -->
This PR adds logic to ensure that internal images always have
width/height when added to the block editor. This is useful because
Next.js requires width/height in order to optimize images
### Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you are unsure about any of these, please ask for
clarification. We are here to help! -->
- [x] I agree to follow this project's [**Code of
Conduct**](https://github.com/10up/.github/blob/trunk/CODE_OF_CONDUCT.md).
- [x] I have updated the documentation accordingly.
- [x] I have added [Critical Flows, Test Cases, and/or End-to-End
Tests](https://10up.github.io/Open-Source-Best-Practices/testing/) to
cover my change.
- [x] All new and existing tests pass.
Copy file name to clipboardExpand all lines: docs/documentation/06-WordPress Integration/gutenberg.md
+24
Original file line number
Diff line number
Diff line change
@@ -110,4 +110,28 @@ $doc = apply_filters(
110
110
$block,
111
111
$block_instance
112
112
);
113
+
```
114
+
115
+
### tenup_headless_wp_ensure_image_dimensions
116
+
117
+
HeadstartWP can automatically add width and height attributes to any internal images in Gutenberg blocks that for some reason is missing width and height attributes to prevent layout shifts. This feature is disabled by default and must be enabled using the `tenup_headless_wp_ensure_image_dimensions` filter. When enabled, it works by:
118
+
119
+
1. Checking if the image already has width and height attributes
120
+
2. If not, attempting to get the image ID from the URL
121
+
3. Using WordPress core functions to add the dimensions and srcset attributes
122
+
123
+
This process is only applied to images hosted on your WordPress site and will be skipped for external images.
124
+
125
+
```php
126
+
/**
127
+
* Filter to enable image dimension processing
128
+
*
129
+
* @param bool $enable Whether to enable adding dimensions, defaults to false
0 commit comments