1

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:

<?php
//DETECT REFERRER
if(empty($_SESSION["referrer"]))
{
    $referrer = $_SERVER["HTTP_REFERER"];
    if(empty($referrer))
        $referrer = $_SERVER["SCRIPT_URI"].((!empty($_SERVER["QUERY_STRING"]))? '?'.$_SERVER["QUERY_STRING"]:'');
    $_SESSION["referrer"] = $referrer;
}
//DETECT AFFILIATE ID 
if(empty($_SESSION["aid"])) 
{ 
    $aid = $_GET["aid"]; 
    if(empty($aid)) 
        $aid = $_COOKIE["aid"]; 
    if(empty($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

1 Answer 1

-1

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.

2
  • 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.
    Commented Mar 12, 2018 at 20:39
  • 1
    This hasn't really answered the question so shouldn't be marked as an answer...
    – rudtek
    Commented Mar 12, 2018 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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