Skip to content

Instantly share code, notes, and snippets.

@mattmorgis
Last active May 8, 2019 15:06
Show Gist options
  • Save mattmorgis/2c4bd1f7d2ca7f318e2a to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment