Skip to content

Instantly share code, notes, and snippets.

@mattmorgis
Last active July 20, 2025 05:59
Show Gist options
  • Select an option

  • Save mattmorgis/2c4bd1f7d2ca7f318e2a to your computer and use it in GitHub Desktop.

Select an option

Save mattmorgis/2c4bd1f7d2ca7f318e2a to your computer and use it in GitHub Desktop.
Display Random Ad (WordPress or HTML)
<script type="text/javascript">
var total_images = 3;
var random_number = Math.floor((Math.random()*total_images));
var random_img = new Array();
random_img[0] = '<a href="http://google.com"><img src="http://domain.com/images/ad1.gif"></a>';
random_img[1] = '<a href="http://google.com"><img src="http://domain.com/images/ad2.gif"></a>';
random_img[2] = '<a href="http://google.com"><img src="http://domain.com/images/ad3.gif"></a>';
document.write(random_img[random_number]);
</script>
@ben-g123
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment