Force the browser to reload the content when using the URL in a link

When you use the URL for a random redirection in a link or button and click several times on that link, the browser might always open the same post/product/… instead of choosing a random item. This is because browsers remember the content for a given URL and load it from a local cache, rather than fetching it each time from the Internet.

To remedy this, you can automatically add a small piece to the URL that changes with every click. This random number has no other effect then forcing the browser to load the content from the server, and that way the plugin can do its work.

Instructions

Insert the following JavaScript snippet into the bottom of the page where you use your link. You need to use the class name “random-link” for that link, or adjust it as needed.((You need some basic knowledge of CSS. If you don’t know what’s going on here, ask your web designer or a tech-savvy friend.))

Plugins like Header Footer Code Manager let you insert snippets into particular pages. Don’t modify the theme templates directly since your changes would be overwritten with the next theme update. If you prefer editing the HTML directly, create a Child Theme first.

Tags: , ,