Set cookie if url parameter exists

I’m trying to set a cookie in wordpress if the url contains a specific parameter;

//Check if partner is referrer
add_action( 'init', 'set_referrer_cookie', 0 );

function set_referrer_cookie() {
    if (!empty($_GET['referer_value'])) {
      $name = 'referer';
      $referer_value = preg_replace('/[^-a-zA-Z0-9_]/', '', $_GET['referer_value']);
  setcookie($name, $referer_value, time() + (86400 * 21), '/');

It works just fine when I set Cloudflare to development mode but as soon as I switch off development mode, the cookie isn’t set. Does anyone know what feature is being switched off in development mode that allows for this to work?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.