Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

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?

1 Answer

0 votes
by (106k points)

There are many ways to solve this issue that you are facing. The first thing you can go for a plugin:

Or You can code manually below is the link you can check-out:

Another way to solve this issue would be to add the following code in function.php:-

add_filter( 'query_vars', 'addnew_query_vars', 10, 1 );

function addnew_query_vars($vars)

{

$vars[]='var1';//var1 is the name of the variable you want to add 

return $vars; 

}

If you will use this code then you will be able to use $_GET['var1'] that you want to use in your code.

Related questions

+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 6, 2019 in Web Technology by Sammy (47.6k points)
+1 vote
1 answer

Browse Categories

...