How to Change a Section Background Image with URL Parameters

Follow

Like Dynamic Text Replacement for text, this script changes the background image of a page section based on a URL parameter. You can match the hero image to the ad or email a visitor clicked, without building a separate page for each.

Demo page showing buttons to switch background images using URL parameters: Vancouver, Montreal, Hot Dog, Real Dog.

See the demo page built in Unbounce.

This is community code, not an official Unbounce feature. Unbounce Support can't troubleshoot custom code. Test it on a published page before relying on it, and work with a developer if you aren't comfortable editing HTML, JavaScript, and CSS.

Add the background swap to your page

  1. Copy the script from this GitHub gist and add it to the JavaScripts section with placement set to Before Body End Tag.
  2. On line 7 of the script, replace lp-pom-block-8 with the ID of your page section.
  3. Host your background images outside Unbounce, for example on Dropbox or Imgur. Images uploaded to Unbounce can't be used, because their URLs can change and the script needs a stable URL to add to the page URL.
  4. Build your page URLs. Add the image URL to the end of the page URL as the background parameter, for example www.yourdomain.com/landing-1/?background=IMAGE-URL.

To get an image's URL, right-click the image and select Copy image address. Only use images you own the rights to or that are in the public domain. Animated GIFs also work.

Earth viewed from space showing North America, blue oceans, and white clouds against a black background

Test the change

Run an A/B test with a small share of traffic to confirm the change doesn't lower your conversion rate.