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

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

How to Use Cookies Within WordPress

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:

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.

Rate this Tutorial:
No CommentsLeave a Comment

Other (182)

Popular Keywords