I'm currently having issues with a site which is not able to be indexed due to a cookie redirect function that's in place.
To summarize; when a user lands on the webpage for the first time they will be redirected to a splash page. Once they have visited this page once it will be stored in their cookies so that any subsequent visits mean they will be directed to the main homepage.
The code in place to achieve this is the following:
function check_for_redirect() {
$days_to_expire = 30;
if (!is_admin() && !isset($_COOKIE['already_visited'])) {
setcookie('already_visited', true, time() + 86400 * $days_to_expire);
wp_redirect('https://website.com/splash', 302);
exit;
}
}
add_action('init', 'check_for_redirect');
The code seems to work fine but I have noticed then when trying to submit my sitemaps.xml file to Google Search Console, it throws an error and seems unable to crawl the site.
Like wise when trying to post a link from the site onto Facebook, the splash page is getting referenced as though the Facebook crawlers are unable to get access to the links
Does anyone have any suggestions on how to get around these issues. I have looked into adding a line into the robots.txt file which would disallow Facebook crawlers from the /splash URL. But not sure if this is the best solution
Any advice would be much appreciated.