This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

Image Url passed to Less variable not visible

7 years ago · Last reply by abyshakes 7 years ago

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.

Need fast email support? Get SiteOrigin Premium

Replies

2
  1. Alex S Staff 7 years, 7 months ago

    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. abyshakes 7 years, 7 months ago

    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.

Have a different question or issue?

Start New Thread