Skip to content

Commit 0a06c63

Browse files
Add default suffix for container
1 parent 3163d47 commit 0a06c63

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

php/integrations/class-elementor.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,20 @@ public function replace_background_images_in_css( $post_css, $element ) {
8484
}
8585

8686
foreach ( self::ELEMENTOR_BACKGROUND_IMAGES as $background_key => $background_data ) {
87-
$background = null;
87+
$background = null;
88+
$is_container = false;
8889

8990
if ( isset( $settings[ $background_key ] ) ) {
9091
// Elementor section/column elements store background settings without a leading underscore.
91-
$background = $settings[ $background_key ];
92+
$background = $settings[ $background_key ];
93+
$is_container = true;
9294
} elseif ( isset( $settings[ '_' . $background_key ] ) ) {
9395
// Elementor basic elements (e.g. heading) store background settings with a leading underscore.
9496
$background = $settings[ '_' . $background_key ];
9597
}
9698

9799
// If this specific background setting is not set, we can skip it and check for the next setting.
98-
if ( empty( $background ) || ! isset( $background['id'] ) ) {
100+
if ( empty( $background ) || empty( $background['id'] ) ) {
99101
continue;
100102
}
101103

@@ -110,9 +112,18 @@ public function replace_background_images_in_css( $post_css, $element ) {
110112
// Generate the Cloudinary URL.
111113
$cloudinary_url = $media->cloudinary_url( $media_id, $media_size );
112114

115+
// If URL generation failed, we should leave the original URL within the CSS.
116+
if ( empty( $cloudinary_url ) ) {
117+
continue;
118+
}
119+
113120
// Build the CSS selector and rule.
114-
$css_selector = $post_css->get_element_unique_selector( $element ) . $background_data['suffix'];
115-
$css_rule = array( 'background-image' => "url('$cloudinary_url')" );
121+
$unique_selector = $post_css->get_element_unique_selector( $element );
122+
123+
// Elementor applies this suffix rule to container background images to avoid conflicts with motion effects backgrounds.
124+
$default_suffix = $is_container ? ':not(.elementor-motion-effects-element-type-background)' : '';
125+
$css_selector = $unique_selector . $default_suffix . $background_data['suffix'];
126+
$css_rule = array( 'background-image' => "url('$cloudinary_url')" );
116127

117128
// Retrieve the specific media query rule for non-desktop devices.
118129
$media_query = null;

0 commit comments

Comments
 (0)