1. WordPress Snippets

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.
if (strpos($_SERVER[HTTP_REFERER], "google") == true) {
   // Your Message Here
}
Comments to: Detect User from Google Search in WordPress

Your email address will not be published. Required fields are marked *