WordPress – working with cookies – Javascript

At the clientside, WordPress using Javascript to work in the front end.  Obviously you can use jQuery as well.

Writing Cookies
writeCookie = function(cname, cvalue, days) {
    var dt, expires;
    dt = new Date();
    dt.setTime(dt.getTime()+(days*24*60*60*1000));
    expires = “; expires=”+dt.toGMTString();
   document.cookie = cname+”=”+cvalue+expires+’; domain=bluelily.com.au’;
}

Reading Cookies
function readCookie(name) {
     var nameEQ = name + “=”;
     var ca = document.cookie.split(‘;’);
     for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==’ ‘) c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
       }
return null;
}

Deleting Cookies
setCookie(name, “”, null , null , null, 1);

Adwords (1)

Branding (13)

CMS (3)

CSS (6)

Graphic Design (6)

Javascript (1)

PHP (3)

SEO (5)

tech support (5)

Web Design (10)

Web Development (10)

Wordpress (17)

Wordpress plugins (3)