K
K
KoystrubVS2018-07-19 14:26:49
HTTP Cookies
KoystrubVS, 2018-07-19 14:26:49

Why is Cookie changing in WP?

There is such code in function.php

function app_output_buffer() {
    ob_start();
}
add_action('init', 'app_output_buffer');

add_action( 'wp_head', 'home' );
function home() {
  //Если пост имеет метку город и это не основная страница блога - ставим куку
  if (has_term('gorod', 'post_tag') and !(is_home())) {
        setcookie('city',get_page_uri(), time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false);
    }
}

Everything works, the page starts loading - the cookie is assigned, but after half a second before the end of the full load, the cookie changes to the last blog entry.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question