Skip links

Detect User from Google Search in WordPress

If you work in WordPress and need to show the message for the user who comes from Google search to can convert this user as lead or display newsletter popup.

This code snippet will let you display custom message to user who detected form google search by using HTTP_REFERER variable with PHP where it’s an optional HTTP header field which is linked to the page being requested.

Steps to detect user from google search:

  1. Open WordPress admin panel then go to Appearance > Theme Editor
  2. Open theme index.php file or page you need to display this message like archives for example, if you work localhost open the same file using any code editor IDE
  3. Add the following code at the top of the file.
  4. Save the changes and check your pages by search on Google and open it.

[php]
if (strpos($_SERVER[HTTP_REFERER], "google") == true) {
// Your Message Here
}
[/php]

Leave a comment

Explore
Drag