How to pass extra variables in URL with WordPress
Asked 07 September, 2021
Viewed 3.1K times
  • 53
Votes

I am having trouble trying to pass an extra variable in the url to my WordPress installation.

For example /news?c=123

For some reason, it works only on the website root www.example.com?c=123 but it does not work if the url contains any more information www.example.com/news?c=123. I have the following code in my functions.php file in the theme directory.

if (isset($_GET['c'])) 
{
  setcookie("cCookie", $_GET['c']); 
}

if (isset($_SERVER['HTTP_REFERER']))
{
  setcookie("rCookie", $_SERVER['HTTP_REFERER']);
}

Any Ideas?

9 Answer