@@ -28,6 +28,12 @@ class Elementor extends Integrations {
2828 'background_hover_image_tablet ' ,
2929 'background_image_mobile ' ,
3030 'background_hover_image_mobile ' ,
31+ 'background_overlay_image ' ,
32+ 'background_overlay_hover_image ' ,
33+ 'background_overlay_image_tablet ' ,
34+ 'background_overlay_hover_image_tablet ' ,
35+ 'background_overlay_image_mobile ' ,
36+ 'background_overlay_hover_image_mobile ' ,
3137 );
3238
3339 /**
@@ -109,10 +115,10 @@ public function replace_background_images_in_css( $post_css, $element ) {
109115 return ;
110116 }
111117
112- // Determine if it's a hover background.
113- $ is_hover = ( strpos ( $ background_key , 'hover ' ) !== false );
114-
115- $ css_selector = $ this ->build_background_image_css_selector ( $ unique_selector , $ is_container , $ is_hover );
118+ // Build the CSS selector and rule for background image replacement .
119+ $ is_hover = ( strpos ( $ background_key , 'hover ' ) !== false );
120+ $ is_overlay = ( strpos ( $ background_key , ' overlay ' ) !== false );
121+ $ css_selector = $ this ->build_background_image_css_selector ( $ unique_selector , $ is_container , $ is_hover, $ is_overlay );
116122 $ css_rule = array ( 'background-image ' => "url(' $ cloudinary_url') " );
117123
118124 // Retrieve the specific media query rule for non-desktop devices based on the setting key.
@@ -188,14 +194,42 @@ private function override_elementor_css_rule( $post_css, $css_selector, $css_rul
188194
189195 /**
190196 * Build the full CSS selector for background image replacement.
197+ * We try to match the exact Elementor formatting and rules, so that our CSS overrides the previous rules,
198+ * instead of adding new rules within the CSS which may not apply for specific edge cases (e.g. specific child elements).
191199 *
192200 * @param string $unique_selector The unique selector for the element.
193201 * @param bool $is_container Whether the element is a container (section/column).
194202 * @param bool $is_hover Whether the background is for hover state.
203+ * @param bool $is_overlay Whether the background is for an overlay.
195204 *
196205 * @return string
197206 */
198- private function build_background_image_css_selector ( $ unique_selector , $ is_container , $ is_hover ) {
207+ private function build_background_image_css_selector ( $ unique_selector , $ is_container , $ is_hover , $ is_overlay ) {
208+ if ( $ is_overlay ) {
209+ // Overlay backgrounds need to target multiple pseudo-elements and child elements.
210+ $ overlay_selector = sprintf (
211+ '%1$s%2$s::before,
212+ %1$s%2$s > .elementor-background-video-container::before,
213+ %1$s%2$s > .e-con-inner > .elementor-background-video-container::before,
214+ %1$s > .elementor-background-slideshow%2$s::before,
215+ %1$s > .e-con-inner > .elementor-background-slideshow%2$s::before ' ,
216+ $ unique_selector ,
217+ $ is_hover ? ':hover ' : ''
218+ );
219+
220+ // For non-hover overlays, we need to also target motion effects layers.
221+ if ( ! $ is_hover ) {
222+ $ overlay_selector = sprintf (
223+ '%1$s,
224+ %2$s > .elementor-motion-effects-container > .elementor-motion-effects-layer::before ' ,
225+ $ overlay_selector ,
226+ $ unique_selector
227+ );
228+ }
229+
230+ // Replace any newline and extra spaces to match the exact Elementor formatting.
231+ return preg_replace ( '/\s+/ ' , ' ' , $ overlay_selector );
232+ }
199233 // For hover backgrounds, we simply append :hover to the unique selector.
200234 if ( $ is_hover ) {
201235 return $ unique_selector . ':hover ' ;
@@ -206,7 +240,7 @@ private function build_background_image_css_selector( $unique_selector, $is_cont
206240 return $ unique_selector ;
207241 }
208242
209- // For container elements, we need to replicate the specific selector Elementor uses for background images .
243+ // For container elements, we need to target both the element itself and its motion effects layers .
210244 return sprintf (
211245 '%1$s:not(.elementor-motion-effects-element-type-background), %1$s > .elementor-motion-effects-container > .elementor-motion-effects-layer ' ,
212246 $ unique_selector
0 commit comments