Wordpress

Set cookies in wordpress

set cookies in wordpress to pop msg if new visitor .

in function.php write the code below :

function bloggolfoy_set_new_user_cookie() {
if ( ! is_admin() && ! isset( $_COOKIE[‘bloggolfoy_new_visitor’] ) ) {
setcookie( ‘bloggolfoy_new_visitor’, 1, time() + 3600 * 24 * 10, COOKIEPATH, COOKIE_DOMAIN, false );
}
}
add_action( ‘init’, ‘bloggolfoy_set_new_user_cookie’);

now where you have coded popup : write

<?php if ( isset( $_COOKIE[‘bloggolfoy_new_visitor’] ) ) {

// echo ‘Welcome back!’;

} else {?> script code to pop <?php } ?>

Leave a Reply

Your email address will not be published. Required fields are marked *