I've made a WordPress site. Before, I had a coded site in HTML. My new WordPress site is still in maintenance mode. But, I want to insert a PHP code above all the website content. This is my code:

    $referrer = $_SERVER["HTTP_REFERER"];
        $referrer = $_SERVER["SCRIPT_URI"].((!empty($_SERVER["QUERY_STRING"]))? '?'.$_SERVER["QUERY_STRING"]:'');
    $_SESSION["referrer"] = $referrer;
    $aid = $_GET["aid"]; 
        $aid = $_COOKIE["aid"]; 
        $aid = 1; 
    setcookie("aid", $aid, strtotime("+10 years"), "/"); 
    $_SESSION["aid"] = $aid; 

But I don't know how to insert it in avery page on my site. Is there any way to do this? If that's not possible, is there a different way to get a cookie when a query string is in the URL? Thanks in advance.

Regards, Luuk Faasse


WordPress theme should load header.php file for eacfront-endnd request, so the best place to add your custom code is in the header.php on the very top, before any HTML.

  • Thanks! But, now I have to insert a code that prints the value of the cookie. I have a code for that, but how to insert that into my page? – Luuk F. Mar 12 '18 at 20:39
  • 1
    This hasn't really answered the question so shouldn't be marked as an answer... – rudtek Mar 12 '18 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.