Skip to content

Instantly share code, notes, and snippets.

@wvuwebgist
Last active February 23, 2021 22:19
Show Gist options
  • Save wvuwebgist/cc5cb00847eb166f5346f3c79be7fb73 to your computer and use it in GitHub Desktop.
Save wvuwebgist/cc5cb00847eb166f5346f3c79be7fb73 to your computer and use it in GitHub Desktop.
Generate a URL to a background image from a label and output that to a style tag in the head (Liquid).
{% assign background1 = site | first_random_image_tagged_with: label: "backpage-1-hero" | image_url: size: "1780x580" %}
<style>
.example {
background-image: url('{{ background1 }}');
}
</style>
<!-- OR: -->
{% assign background2 = site | first_random_image_tagged_with: label: "backpage-1-hero" | image_url: size: "1780x580" | css_background_image %}
<style>
.example {
{{ background2 }}
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment