Smaller background images

0.0/5
<?php
add_action(	'elementor/element/parse_css', function( $post_css, $element ) {
    /**
    * @var ElementorPost_CSS_File $post_css
    * @var ElementorElement_Base  $element
    */
    $rules = $post_css->get_stylesheet()->get_rules( );
    if( is_array( $rules ) && count( $rules ) ){
        foreach ($rules as $device_key => $device_rules ) {
            if( is_array( $device_rules ) && count( $device_rules ) ){
                foreach ($device_rules as $selector => $styles ) {
                    if( is_array( $styles ) && count( $styles ) ){
                        foreach ($styles as $attr => $val ) {
                            if( $attr == 'background-image' ){
                                $url = str_replace('url(','', $val);
                                $url = str_replace(')','',$url);
                                $url = str_replace("'",'',$url);
                                $url = str_replace('"','',$url);
                                $image_id = attachment_url_to_postid( $url );
                                if( $image_id ){
                                    $image = wp_get_attachment_image_src( $image_id, 'medium-large' );
                                    $post_css->get_stylesheet()->add_rules(
                                        $selector, ['background-image' => 'url(' . $image[0] . ')']
                                    );
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}, 10, 2 );

Comments and reviews

{{ reviewsTotal }} Review
{{ reviewsTotal }} Reviews
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}

Description

Author

Tags