WordPress security
Google sees different content than the user. How to detect cloaking in WordPress
An infected site doesn’t always look broken. It can run fast, display the correct offer and report no errors, yet still serve search engine bots foreign text and links. This kind of cloaking can go unnoticed by the site owner for a long time. Below we describe an anonymised case from our support work. We also show a simple preliminary test, a WordPress file check and the right order of actions after an infection is detected.
Next step
Comparing server responses is a good start, but a full diagnosis also requires checking files, logs and the data recorded in Google Search Console.
01
What cloaking is and what the infection looked like
Cloaking means presenting different content depending on who opens the same URL. An ordinary user may see the company’s correct page, while a search engine bot sees text prepared by the attacker.
With an infection, the goal is often to use the reputation of an existing domain to promote other people’s stores, drugs, casinos, fake investments or other sites. The owner doesn’t see this content in everyday use of the site. The problem only surfaces in Google results, Search Console, logs or when comparing server responses.
What the detected case looked like
We were checking several sites running on one hosting account. One of them wasn’t part of the original report, but we included it in the check because it used the same environment.
The WordPress root directory contained a modified wp-blog-header.php file. This is a core file which, in a clean installation, has a very short and clearly defined role. On the site we examined it contained additional code.
Among other things, the code collected:
- the visitor's IP address,
- the browser identifier,
- the referring page address,
- the browser language.
It then sent this information to an external server. The response it received could replace the correct page content. The address of the command server was encoded, which made it hard to spot when skimming the file.
The most important part of the logic sat outside the infected site. The external server decided who received the correct site and who received the foreign content. For that reason, reading the code fragment alone wasn’t enough to establish all the ways the infection could behave.
02
How to check whether Google receives different content
A preliminary test can be done with curl. The first command sends a request similar to an ordinary browser. The second identifies itself as Googlebot.
curl -fsSL --compressed
-A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/151.0"
https://twojadomena.pl/
| grep -oE '[^<]*'
curl -fsSL --compressed
-A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
https://twojadomena.pl/
| grep -oE '[^<]*'A different title or completely different content is a serious warning sign. In this case an ordinary browser received the name of the institution, while a request with the Googlebot identifier returned a foreign title and an extensive page with links to overseas stores.
It’s also worth checking a variant with a referrer. Some infections only trigger a different response for a visit that resembles search engine traffic.
curl -fsSL --compressed
-A "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)"
-e "https://www.google.com/search?q=przykladowa+fraza"
https://twojadomena.pl/
| head -c 500This test is only a preliminary check. The User-Agent header is easy to fake. A more advanced infection may check Google’s real bot IP address and not return its payload during an ordinary test from the administrator’s computer. Identical results from both commands therefore don’t confirm that the site is clean.
Checking in Google Search Console
A more thorough check can be done in Google Search Console:
- Open the URL Inspection tool.
- Enter the full address of the suspicious page.
- Open the version Google last fetched and choose the option to view the indexed page.
- Check the HTML, the HTTP response and the content recorded during indexing.
- Run the live test and look at the tested page and its screenshot.
Comparing the indexed version, the live test and an ordinary browser gives a much better picture than just changing the identifier in curl.
03
Why an infection can stay invisible
Malicious code can choose the recipient based on several signals at once. As a result, during an ordinary check the site owner sees a correct site:
- a direct visit doesn't trigger the foreign content,
- a known browser receives the correct page,
- traffic from the admin panel may be excluded,
- selected IP addresses may be put on an ignore list,
- the payload may be shown only to bots or only at certain times.
The first visible symptom is often a drop in traffic, foreign titles in search results, new URLs in the index or a message in Search Console. By then the search engine may already have stored the infected content.
Why a single scanner may not be enough
Security scanners are still an important part of protection, but each tool sees only part of the environment.
An external scanner analyses the HTTP response it receives for its own IP address and identifier. If the infection recognises that traffic and returns the correct page, the test may not reveal the problem.
A scanner running as a plugin can compare files, detect known signatures and look for suspicious functions. However, code that communicates with an external API isn’t always malicious. Legitimate integrations, payments and messaging systems use similar functions.
The best result comes from combining several methods:
- comparing HTTP responses,
- Search Console checks,
- checksum verification,
- analysing changed and new files,
- reviewing server and login logs,
- checking every site on the same hosting account.
04
How to check the integrity of WordPress files
If the suspicious code was added to a core file, WP-CLI can detect the change by comparing files with WordPress’s official checksums.
wp core verify-checksums --include-root --version=$(wp core version)The basic check compares known core files, including wp-blog-header.php. The –include-root option also warns about unknown files placed in the root directory, for example next to wp-config.php.
Correct core file checksums don’t rule out the whole infection. Malicious code may be in wp-content, the database, scheduled tasks, configuration files or outside the site directory. The command’s result is proof of the integrity of the scope checked, not a full security certificate for the site.
05
What to do after detecting cloaking
Don’t limit the repair to removing one piece of code. Cloaking is the result of someone gaining access to the site or the server. Without establishing the cause, the problem may return.
1. Preserve material for analysis
Before cleaning, back up files, the database and logs. Record the time of detection, the changed files, the server responses and the accounts whose activity needs checking. The infected copy isn’t for restoring the site later. It’s material needed to establish the source of the incident.
2. Restore files from a trusted source
Core files should be replaced with clean files matching the installed WordPress version. Don’t just cut out the visible fragment by hand, as other changes may remain in the file.
3. Establish how access was gained
You need to check administrator accounts, logins, SSH keys, hosting access, the plugins and themes in use, and the computers of the people managing the site. In the case described, the logs pointed to the use of compromised login credentials. That doesn’t mean, however, that every cloaking case has the same cause.
4. Check the whole environment
If several sites run on one account, each of them needs checking. Shared file permissions, the hosting panel or a single compromised account can allow more than one installation to be changed.
5. Change credentials and close active sessions
Once the material is secured, change the passwords for WordPress, hosting, SSH, FTP, the database and related services. You also need to invalidate active sessions and remove accounts, keys and application passwords that are no longer needed.
6. Confirm the repair using several methods
After cleaning, repeat the response comparison, the checksum verification and the log analysis. Then run the live page test in Search Console. A message saying the scan has finished isn’t a sufficient acceptance criterion on its own.
7. Ask Google to recheck the site
Once the repair is confirmed, you can submit the most important URLs for reindexing. If Search Console shows a security issue or a manual action, use the appropriate review procedure. Google doesn’t always refetch the page immediately.
06
How to reduce the risk of a similar infection
The most important safeguards aren’t complicated, but they have to run continuously:
- update WordPress, themes and plugins,
- remove unused extensions and accounts,
- use two-factor authentication for administrators,
- limit user permissions to their actual duties,
- store backups off the site's server and test restoring them regularly,
- monitor file changes and new accounts,
- periodically compare responses for different types of traffic,
- check indexing status and security issues in Search Console.
07
The key takeaway
A site that looks correct doesn’t confirm that every visitor receives the same content. Cloaking exploits exactly that trust in everyday visual checks.
A simple test with different identifiers can reveal the problem in a few minutes, but it shouldn’t be the only method. The most reliable check combines server responses, Search Console data, file integrity and logs from the whole environment.
Do you suspect Google sees a different version of your site?
We’ll check server responses, file integrity, logs and the site’s status in Search Console. After the analysis you’ll get a list of the changes found, the likely cause of the problem and a plan for cleaning the site safely.
Only 3 required fields · reply within 1 business day · no obligation
