Home / template / Display search terms from google
  • How to Display search terms from google


    Add this PHP snippet to your wordpress theme. When users find your website via Google, the terms they used to find your site will be displayed.

    ( click code to copy )

    wordpress snippet : PHP

             $refer = $_SERVER["HTTP_REFERER"];
             if (strpos($refer, "google")) {
                     $refer_string = parse_url($refer, PHP_URL_QUERY);
                     parse_str($refer_string, $vars);
                     $search_terms = $vars['q'];
                     echo 'Welcome Google visitor! You searched for the following terms to get here: ';
                     echo $search_terms;

    ( WordPress codex functions, hooks, in this snippet. )