Skip to content

Instantly share code, notes, and snippets.

@herbie4
Last active September 22, 2022 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herbie4/84cf0bb1e6b6968d982229fc103dd400 to your computer and use it in GitHub Desktop.
Save herbie4/84cf0bb1e6b6968d982229fc103dd400 to your computer and use it in GitHub Desktop.
Popupmaker plugin: set a auto close time with countdown and option to hide this popup for 1 month, cookie based.
<!-- add this directly into the popup screen of WordPress popupmaker plugin, might need some css styling. -->
<div id="close-auto-text"></div>
<a class="popmake-close pum-close news-popup-close" href="#" onclick="setPUMcookie();">Click here to hide this popup for 1 month.</a>
<code><script>function setPUMcookie() { var CookieDate = new Date;
CookieDate.setFullYear(CookieDate.getFullYear());
document.cookie = "pum-4830=true; expires=' + CookieDate.toUTCString() + '; path=/";}
var timeLeft = 30; var elem = document.getElementById('close-auto-text');
var timerId = setInterval(countdown, 1000);
function countdown() {
if (timeLeft == -1) {
clearTimeout(timerId);
doSomething();
} else {
elem.innerHTML = 'This window will close in ' + timeLeft + ' seconds.';
timeLeft--;
}
}
function doSomething() {
jQuery('.popmake-close').trigger('click');
}
</script></code>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment