Set a cookie inside the 404.php theme page

I’m trying to set a cookie with these code but the cookie is not created

setcookie( ‘name’, ‘carl’, 0, ‘/names’, ‘’, isset($_SERVER[“HTTPS”]), true);

I was looking on the internet a possible solution and I found and try this solution

add_action( ‘init’, ‘wpse8170_init’ );
function wpse8170_init() {
if ( !headers_sent() ) {
setcookie( ‘name’, ‘carl’, 0, ‘/names’, ‘’, isset($_SERVER[“HTTPS”]), true);

But it didn’t work. Please help, I just need a way to create a cookie inside my 404.php theme page and then I will make a redirection to another page of my own website, as the cookie is just to keep the variable for the next page.

Read more here:: Set a cookie inside the 404.php theme page

Leave a Reply

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