We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials
More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsWordPressOther

How to Use Cookies Within WordPress

OpenVZ VPS
Linux KVM Hosting
Windows Cloud Server
Brazil VPS
Germany Cloud Servers
cPanel KVM
Linux Cloud Server
USA VPS
KVM VPS
Ubuntu VPS
Follow These Steps to Use Cookies Within WordPress

Using cookies in WordPress allows us to display different kind of information every time they are visiting the website. In order to set up cookies within WordPress system, you will need to add required lines of code in to themes functions.php file. This file is located in theme directory which can be found navigating to wp-content/themes folder.

WordPress Functions File

Simply connect to the hosting account over FTP or use any file manager available in the control panel and open file functions.php for editing.

Then add the following code inside the file:

1
2
3
4
5
6
function set_newuser_cookie() {
if (!isset($_COOKIE['sitename_newvisitor'])) {
setcookie('sitename_newvisitor', 1, time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false);
}
}
add_action( 'init', 'set_newuser_cookie');

That should be enough for enabling cookies in the WordPress website.

Linux KVM Hosting
Ubuntu VPS
cPanel KVM
Germany Cloud Servers
Brazil VPS
Windows Cloud Server
USA VPS
KVM VPS
Linux Cloud Server
OpenVZ VPS
Rate this Tutorial:
No Comments Leave a Comment
Leave a Comment

Other (182)

Popular Keywords