Yes, if you’re not going to have users login, the best way to save data is via cookie. Some examples here: https://wpengine.com/resources/wordpress-cookies/
Thank you for your help @sterndata. That tutorial is very useful! The only thing I’m unsure of now though is how to remember the user’s page choice. If the cookie is set I’d like it to direct to the SHOP or CORPORATE side of the site (depending on their selection)
You’d need to test the cookie value on your home page, either by using a plugin or putting code into the homepage to redirect based on its value. You may be able to use something off-the-shelf: https://ww.wp.xz.cn/plugins/redirect-by-cookie/, for example
Thank you Steven. I’m looking to do it in the code. I’ve gone into functions.php in my theme directory. I found the code below online (which I’ve adapted slightly) that seems to be close to what I need. I’m not sure exactly what I need changing to make it work though! 🙁
function has_my_cookie()
{
if (!is_admin()){
//Check to see if our cookie is set if not redirect to your desired page and set the cookie
if ( !isset($_COOKIE["sevisitor"])) {
//setcookie
setcookie('sevisitor', 1, time()+1209600, "/", "http://localhost/website/homepage", false);
//Redirect
wp_redirect( get_site_url().'/shop' ); exit;
}
if ( !isset($_COOKIE["sevisitor2"])) {
//setcookie
setcookie('sevisitor2', 1, time()+1209600, "/", "http://localhost/website/homepage", false);
//Redirect
wp_redirect( get_site_url().'/corporate' ); exit;
}
}
}
add_action('init', 'has_my_cookie');
-
This reply was modified 5 years, 4 months ago by
gareth94.
-
This reply was modified 5 years, 4 months ago by
gareth94.