Home>Support>Image Url passed to Less variable not visible

Image Url passed to Less variable not visible

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

Hi,

I’ve created a custom widget as per your documentation and I have a field for a background image which needs to be pushed to a LESS variable.

I’ve included the following in the main Widget Class

    
    function get_less_variables( $instance ) {
        return array(
            "bg_image1" => wp_get_attachment_image_url($instance['slider_image1']),
            "bg_image2" => wp_get_attachment_image_url($instance['slider_image2'])
        );
    }

And also have the following in LESS file


bg_image1: "http://mysite.test/minisite/wp-content/uploads/sites/2/2018/05/MainPhoto_1-2-150x150.jpg";
@bg_image2: "http://mysite.test/minisite/wp-content/uploads/sites/2/2018/05/MainPhoto_1-2-150x150.jpg";


@media only screen and (max-width: 320px) {
        
    #slider0 {background-image: url( "@{bg_image1}" );}
    
    #slider1 {background-image: url( "@{bg_image2}" );}
    
}
@media only screen and (min-width: 1025px) {
    
    #slider0 {background-image: url( "@{bg_image1}" );}
    
    #slider1 {background-image: url( "@{bg_image2}" );}
    
}

And the image URL doesnt turn up. However, if I remove wp_get_attachment_image_url from the main class I’m able to see the Attachement ID come up in the CSS generated. Weird, I’ve tried other functions too but I’m unable to get the image URL shown in the LESS file. Is there a way for me to Debug the LESS compilation, any pointers will be helpful.

Thanks in advance.
Abyshakes

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 7 years, 22 days ago Alex S
    Hi, I Work Here

    Hi Abyshakes,

    Unfortunately, I don’t think this is currently possible at this time – I’ve tried this in the past and ran into issues also. The lead developer wasn’t sure if this was possible so he’s going to run a few tests to confirm if this is the possible or not. I know none of our widgets do this. Instead, we set the image inline. I know that’s maybe not ideal and for that, I’m sorry.

  2. 7 years, 21 days ago abyshakes

    Thanks a lot for taking the time to reply, I did include them inline and it works :)

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More