jQuery Cookie Popup: Show a Popup Once Per Day (Easy 3-Step Snippet)

JQuery Set Cookies Popup Setup One Day

Quick answer: A jQuery cookie popup shows a message on the first visit and then saves a cookie when the visitor closes it, so it stays hidden for a set time, here one day. Add the HTML to your footer, the CSS to your stylesheet and the jQuery snippet below. No plugin is needed.

jQuery cookie popup that shows once per day

It shows a popup when someone first visits your site, and when they close it, saves a small cookie so the popup stays hidden for one day. Use it for a cookie notice, a newsletter offer or an announcement. Change one number to make it hide for a week or a month instead.

Step 1: Add the popup HTML

Put this in your footer (for example footer.php before wp_footer()) so it loads on every page.

footer.php
<div class="popup-overlay" role="dialog" aria-modal="true" aria-labelledby="popup-title">
  <div class="popup">
    <button type="button" class="close" aria-label="Close">×</button>
    <h2 id="popup-title">We use cookies</h2>
    <div class="popupset">
      <p>We use cookies to improve your experience on this site.</p>
      <a href="#" class="submit">OK, got it</a>
    </div>
  </div>
</div>

Step 2: Add the CSS

style.css
.popup-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.6);align-items:center;justify-content:center;z-index:9999}
.popup{position:relative;background:#fff;color:#222;width:90%;max-width:420px;padding:28px;border-radius:12px}
.popup .close{position:absolute;top:8px;right:12px;border:0;background:none;font-size:28px;line-height:1;cursor:pointer}
.popupset .submit{display:inline-block;margin-top:12px;padding:10px 18px;border-radius:6px;background:#3d5afe;color:#fff;text-decoration:none}

WordPress already loads jQuery on most themes. Wrapping the code in jQuery(function ($) { ... }) makes $ safe to use and waits until the page is ready.

cookie-popup.js
jQuery(function ($) {
  var COOKIE = 'popupClosed';
  var DAYS   = 1; // show the popup again after 1 day

  function getCookie(name) {
    var match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
    return match ? decodeURIComponent(match[1]) : '';
  }

  function setCookie(name, value, days) {
    var d = new Date();
    d.setTime(d.getTime() + days * 24 * 60 * 60 * 1000);
    document.cookie = name + '=' + encodeURIComponent(value) +
      '; expires=' + d.toUTCString() + '; path=/; SameSite=Lax';
  }

  var $overlay = $('.popup-overlay');
  if (getCookie(COOKIE) !== '1') {
    $overlay.css('display', 'flex');
  }

  function closePopup(e) {
    if (e) e.preventDefault();
    setCookie(COOKIE, '1', DAYS);
    $overlay.fadeOut();
  }

  // Close with the X, the button, a click outside the box, or the Escape key
  $overlay.on('click', '.close, .popupset a', closePopup);
  $overlay.on('click', function (e) { if (e.target === this) closePopup(e); });
  $(document).on('keydown', function (e) { if (e.key === 'Escape') closePopup(); });
});

How the code works

  • getCookie() checks whether the visitor already closed the popup.
  • If not, the overlay is shown with display:flex so the box is centred.
  • Any way of closing it calls setCookie(), which stores popupClosed=1 for the number of days in DAYS.
  • SameSite=Lax and path=/ make the cookie work across your whole site in modern browsers. The details are explained on MDN’s document.cookie page.

Change how often the popup appears

  • Once a week: set DAYS = 7.
  • Once per browser session: remove the expires part from setCookie().
  • Every visit (for testing): delete the cookie in your browser’s developer tools.

No. This popup is a notice. Legal consent under GDPR means blocking analytics and marketing cookies until the visitor agrees and storing that choice. For that, use a proper consent management plugin, and use this snippet for announcements and offers.

Frequently asked questions

How do I show a popup only once per day with jQuery?

Save a cookie with a one-day expiry when the visitor closes the popup, and only show the popup if that cookie is missing. The snippet above does this with getCookie() and setCookie().

Does this cookie popup need a plugin?

No. It is plain HTML, CSS and jQuery that you can add to any WordPress theme.

Why does the popup show again after clearing cookies?

The popup relies on a browser cookie. When the visitor clears cookies or uses another browser, the cookie is gone, so the popup appears again.

Need a custom popup, offer bar or consent setup? Get a free quote.

Need help with your own site? Get a free quote or see my recent builds.

Tanvir Hossain Tofan, WordPress developer

Written by Tanvir Hossain Tofan

WordPress & Shopify developer from Bangladesh with 5+ years of experience building custom ACF themes, Elementor sites, plugins and Shopify stores for clients worldwide. Author of the Toofan Stage-to-Live Sync and Talkvara AI Chatbot plugins on WordPress.org.

See my work · Hire me · WhatsApp · YouTube · LinkedIn

Previous Post

Copy Link to Clipboard in WordPress: Easy Share Button in 3 Steps

Add a copy link to clipboard button in WordPress w ...

Next Post

Best Web Developer in Bangladesh: How to Find the Top Talent for Your Business

Quick answer: The best web developer in Bangladesh ...

If you find it useful

Buy me a coffee

ACF

Blog

Elementor

HTML JQuery

PHP

Tips & Tricks

WordPress

Copy Link to Clipboard in WordPress: Easy Share Button in 3 Steps

Add a copy link to clipboard button in WordPress w ...

jQuery Tabs Next Prev Button: Step-by-Step Form with Bootstrap Tabs

Add Next and Previous buttons to Bootstrap tabs wi ...

Back to top