init
is too early (it happens before the main query), use the action template_redirect
instead.
And for the ID use get_the_ID()
.
Example:
if ( is_singular() )
setcookie( get_the_ID(), 'visited',time() + ( DAY_IN_SECONDS * 31 ) );
init
is too early (it happens before the main query), use the action template_redirect
instead.
And for the ID use get_the_ID()
.
Example:
if ( is_singular() )
setcookie( get_the_ID(), 'visited',time() + ( DAY_IN_SECONDS * 31 ) );