Similar to Dynamic Image Replacement, this script will allow you to also swap out different images on the page based on a URL parameter.
The code is actually quite simple. By including a image’s source URL as a value of a specific URL parameter you can swap it out with a default image on the page (which has been added via the page builder).
You can see this in action (built in Unbounce) here:
WARNING: YOU ARE ENTERING DEVELOPER TERRITORY
Add the script from here:
Add a default image(s) to the page using the image widget in the page builder. Update the script with the ID of the default images on the page you’d like to swap based on a URL parameter.
Decide on a URL parameter you would like to use to pass through the new image URL and update the script in the
//Add parameters section.
For example you could assign a parameter of “image” and then format a URL like so:
In this case the code would look like:
> // Add URL parameters > var img1 = getURLParameter('image');
Create your URL using the source of the image you’d to replace.
PROTIP Use a URL shortener for the image source in the URL to keep is cleaner and shorter
- The dynamic image will keep the same dimensions of the default image added via the builder. So make sure your images are all the same size and resolution to avoid stretching and zooming.
- In order to add multiple images simply create more variable in the code for the default images and parameters (the default script has two).
Want to take your Unbounce landing pages + Convertables™ to the next level?
Check out the Ultimate List of Unbounce Tips, Scripts & Hacks