Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

apply bunny image class to image element

  • Hello

    I have Bunny.net CDN for image processing and need the image url to have a class like this for example domain.com/image.jpg?class=square so it can crop and process the image.

    Is it possible to apply this to Image Block with GenerateBlocks Pro?

    Thank you

  • Hi there,

    you can manually add a URL to a GB Image Block, its the Insert from URL option when you add the image block to the page. But that would be a manual process.

    How many images will require this ? As it may be possible to filter the query var into the URL.
    And if there are many images they would need some common class or attribute to do this.

    Let me know.

  • Hi David

    Yes, i want to apply the class automatically for all images.

    I already built some custom image classes in Bunny for example ?class=ratio4-3, ?class=square …

  • Ok… but if theres multiple class queries. i assume you would need to select which class query is applied to each image ?

  • yes exactly. each image only needs one class

  • Sorry for all the questions… but how would it know which class to add?

  • can i define class name in image block setting.

    For example an attribute let’s say image class = square, then the final image URL will be appended with domain.com/abc.jpg?class=square

  • Try this PHP, you can add pre-defined class name like “square” and “rectangle”, feel free to change/add class name.

    function add_custom_parameter_to_image_url($url, $attributes) {
        if (!empty($url) && !empty($attributes['className'])) {
            if (strpos($attributes['className'], 'square') !== false) {
                $url = add_query_arg('class', 'square', $url);
            } elseif (strpos($attributes['className'], 'rectangle') !== false) {
                $url = add_query_arg('class', 'rectangle', $url);
            }
        }
        return $url;
    }
    
    add_filter('generateblocks_dynamic_url_output', 'add_custom_parameter_to_image_url', 10, 2);
    

    And set the GB image block’s dynamic link to single image.

  • thank you, how to choose the class when adding image?

  • how to choose the class when adding image?

    That should be a question for you, you are the one who defines the image sizes based on the classes provided by the plugin.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.