Wordpress category redirection with cookies

What I want to achieve: When a person comes to the site and selects a certain category, the next time they come to the site (returning user), the page will open in this category.

I think that it would be quite easy to do this by setting a cookie when the visitor clicks on the category link (or when the category page loads). The next time they return, the cookie will be read, and then the page will be redirected accordingly.

Unfortunately, my knowledge of PHP and cookies is limited (hence the search for answers), so I need to ask if anyone can help me!

Does anyone have any ideas?

Thank!

+3
source share
2 answers

, , cookie , , , , :

  <?php
    $expire=time()+60*60*24*30;
    setcookie("cat", "/cat1", $expire);
  ?>

, , , cookie.

<?php
   if (isset($_COOKIE["cat"]))
   {
       //Redirect to that page stored in the cookie
       $_COOKIE["cat"]; //Theres what you need you can handle the redirect how you like
   }
?>
+2

.

0

Source: https://habr.com/ru/post/1735761/


All Articles