Twitter Bootstrap Modal and Jquery Cookie Plugin Twitter Bootstrap Modal and Jquery Cookie Plugin wordpress wordpress

Twitter Bootstrap Modal and Jquery Cookie Plugin


First you need to include the JQuery cookie plugin like so:

<script src="/path/to/jquery.cookie.js"></script>

Then the following code should help you:

<script type="text/javascript">$(function(){    // If the cookie does not exist    if ($.cookie('modalshow') === null)     {       // Show the modal       $('#myModal').modal('show');       var expiryDate = new Date();       var hours = 168;       expiryDate.setTime(expiryDate.getTime() + (hours * 3600 * 1000));       // Create cookie to expire in 168 hours (1 week)       $.cookie("modalshow", "false", { path: '/', expires: expiryDate });    }});</script>


same as @mccanff answer but without using external libs

if (document.cookie.indexOf("modalshow=true") < 0) {    $('#myModal').modal('show');    var expiryDate = new Date();    var hours = 168;    expiryDate.setTime(expiryDate.getTime() + (hours * 3600 * 1000));    document.cookie = "modalshow=true; expires=" + expiryDate + "; path=/";}