Reputation: 141
title says it all.
The visitors that comes to the index page of the Wordpress should be redirected to other page only the first time.
What is the easiest way to achieve this with cookies?
Upvotes: 0
Views: 1917
Reputation: 1169
Try adding the following to the functions.php file of your theme:
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('http://www.example.com', 302); //change the URL and status to whatever you want
exit;
}
}
add_action('init', 'check_for_redirect');
Upvotes: 3