Skip to content

Commit 6dd0062

Browse files
Update widget DOM optimization (#308)
1 parent 38df733 commit 6dd0062

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/widgets/widget-inner-wrapper.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,37 @@ The optimized markup has only one wrapping element:
2828
</div>
2929
```
3030

31-
By default, Elementor uses the unoptimized markup for backwards compatibility.
31+
Elementor had previously utilized unoptimized markup. Nowadays, the only websites with unoptimized markup are those that have deactivated the "Optimized DOM" feature. When enough addons have embraced this feature, Elementor will activate it on all websites.
32+
33+
### Wrapping Elements
34+
35+
The number of wrapping elements that each widget needs is up to the widget developer.
36+
37+
If it's a legacy widget that requires both `<div>` wrappers, add the following method to the widget:
38+
39+
```php
40+
public function has_widget_inner_wrapper(): bool {
41+
return true;
42+
}
43+
```
44+
45+
If it's a new widget that can work with only the outer `<div>` wrapper, without the inner `.elementor-widget-container` wrapper, add the following method to the widget:
46+
47+
```php
48+
public function has_widget_inner_wrapper(): bool {
49+
return false;
50+
}
51+
```
52+
53+
If it's a legacy widget that was already optimized, and prefer to leave the choice to the website, based on the feature activation status, add the following method to the widget:
54+
55+
```php
56+
public function has_widget_inner_wrapper(): bool {
57+
return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
58+
}
59+
```
60+
61+
Whether the experiment is running or not, widgets that do not employ the `has_widget_inner_wrapper()` function will behave like unoptimized widgets with two wrapping `<div>` elements for backward compatibility.
3262

3363
## Examples
3464

0 commit comments

Comments
 (0)