The database
Appended to post content, saved in a Custom HTML or Text widget, or stored in an option that a theme prints in every page. Often encoded with String.fromCharCode or atob() so no address is readable. No file scan sees it.
Guide · Strange pop-ups
A pop-up you never added — an ad, a fake prize, a “click allow to continue” notification prompt, a new tab opening to a betting or dating site — is one of the most common signs that a WordPress site has been hacked. It is also one of the easiest to misread. The attacker’s script is usually written to stay out of your sight: it skips logged-in administrators, shows once per visitor per day, or only fires on phones or for visitors arriving from Google. And sometimes the pop-up is not on the site at all, but in the browser of the person who reported it. This guide shows how to tell those apart in a few minutes, where the injected script lives in WordPress, how to find it without changing anything, and what has to happen after you delete it so it does not come back next week.
Published Last reviewed
Step one
Two minutes here saves hours of searching a clean site. Adware and notification spam on a visitor’s own device look exactly like site malware to the person who sees them.
Open the site in a private window on a phone on mobile data, or on a computer that is not the one that showed the pop-up. Visit two or three pages, then come back an hour later, because many injections show only once per visitor.
If the pop-up appears on a clean device, the site is the source. If it appears only on one computer, keep reading this step.
If the same kind of ad or prompt appears on unrelated, reputable sites as well, the problem is that browser: an extension, or a site that was once allowed to send notifications. In Chrome, check Settings → Privacy and security → Site settings → Notifications, and remove anything you do not recognise, then review the extensions list.
Which device and browser, which page, what the pop-up said, and whether they arrived from Google, an email or by typing the address. A pop-up reported only by visitors from Google is a strong sign of a cloaked injection on the site.
Where it lives
Most site-side pop-ups are a short piece of JavaScript that loads the real advert or prompt from someone else’s server. It has to be printed into your pages from somewhere, and in WordPress that somewhere is one of these.
Figure 1 · Where an unwanted pop-up comes from
Five sources of a pop-up you never added, and how to tell them apart.
| Source | The sign that points to it | Where to look |
|---|---|---|
| Adware on your own device | Pop-ups on other websites too, or only in one browser | Browser extensions and notification settings |
| Script in the database | fromCharCode or an unknown <script src> in page source; files are clean | Posts, widgets, options |
| Modified theme or plugin file | Script appears on every page, survives a database restore | header.php, footer.php, functions.php |
| Hijacked header or footer snippet | A snippet you did not add in a code-injection plugin | Snippet and header/footer plugin settings |
| Compromised third-party script | Began with no change on your side; many sites affected | Ad, chat and analytics tags |
Appended to post content, saved in a Custom HTML or Text widget, or stored in an option that a theme prints in every page. Often encoded with String.fromCharCode or atob() so no address is readable. No file scan sees it.
An extra <script> line in header.php or footer.php, or PHP in functions.php that echoes a script on the wp_head or wp_footer hook. Nulled “free” copies of paid themes often ship with this already inside.
Code-injection and snippet plugins are legitimate, which is exactly why attackers with an administrator login use them: a new snippet survives theme changes and looks like site configuration.
Pop-up builders store custom JavaScript by design. The December 2023 Balada Injector wave planted its script through Popup Builder (CVE-2023-6000, versions 4.2.3 and older), in a field that site owners rarely open.
An ad network, chat widget or analytics tag that was itself compromised, or a domain a script used to load from that has since expired and been bought by someone else. Nothing on your server changed.
Find it
Each command below only reads. Run them from the WordPress root with WP-CLI, over SSH or your host’s terminal. If you cannot use a terminal, skip to the last step: the page source alone is often enough to know what you are dealing with.
Request the home page as a logged-out phone visitor arriving from Google, and save the result for comparison:
curl -s -A "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148" -e "https://www.google.com/" https://example.com/ -o visitor.html
curl -s https://example.com/ -o plain.html
diff <(grep -o "<script[^>]*>" plain.html | sort -u) <(grep -o "<script[^>]*>" visitor.html | sort -u)
Replace example.com with your domain. Any script that appears only in the visitor copy is being served conditionally, which legitimate plugins rarely do.
From the saved copy, list where each script comes from and look for domains you do not recognise:
grep -o '<script[^>]*src="[^"]*"' visitor.html | sed 's/.*src="//; s/"$//' | sort -u
Your own domain, a CDN you chose, and the services you signed up for are expected. A random-looking domain, or an IP address, is the lead to follow.
WP-CLI searches every table, including widgets, options and page-builder data:
wp db search "fromCharCode" --all-tables-with-prefix
wp db search "<script" --all-tables-with-prefix --stats
wp db search "atob(" --all-tables-with-prefix
Expect a few legitimate matches from embedded forms or analytics. Judge each by where its script loads from, and note the table and column of every suspicious one.
Look for script tags and output hooks added recently:
grep -rn --include=*.php -E "wp_head|wp_footer" wp-content/themes/ | grep -iE "script|eval|base64" | head -50
find wp-content -name "*.php" -mtime -30 -printf "%TY-%Tm-%Td %p\n" | sort -r | head -40
wp core verify-checksums
wp plugin verify-checksums --all
verify-checksums compares Core and WordPress.org plugins against the official copies; anything listed as modified deserves a closer look. Premium plugins are not covered and need comparing with a fresh download.
Open each code-snippet, header/footer and pop-up plugin you have installed and read every snippet, custom JavaScript field and “custom code” box. List the plugins first:
wp plugin list --fields=name,status,version,update_version
A snippet you did not write, or a pop-up campaign you did not create, is the injection. Note its creation date: it bounds the time window to search the logs for.
Remove it
Deleting the script takes minutes. Whether it comes back depends on the rest of this list.
Export the database and archive wp-content outside the web root. You will want them to find the way in, and to prove the site was cleaned.
mkdir -p ~/incident
wp db export ~/incident/before-cleanup.sql
tar -czf ~/incident/wp-content.tgz wp-content
Replace modified Core and plugin files with clean copies rather than editing them. Remove the script from the database with WP-CLI search-replace after a dry run, never a raw SQL REPLACE, because widget and option data is serialised and breaks when edited by hand. Delete rogue snippets and pop-up campaigns.
A script in many posts at once, or in a theme file, means someone had write access. Look for administrators you did not create, PHP files in uploads, files in mu-plugins, and an outdated plugin with a known vulnerability. If you find none of these, assume a stolen password.
Update or remove the vulnerable plugin or theme. Change every administrator password and remove unused accounts. Change the database password and the WordPress salts in wp-config.php so stolen sessions stop working.
Repeat the visitor curl and the database search the next day. A pop-up that returns after a careful cleanup means a backdoor or scheduled task survived, which is a different problem from the pop-up itself.
Why it matters
Fake virus warnings, prize scams and push-notification prompts target the people who trust your site. Some lead to malware downloads or payment fraud.
Google Safe Browsing flags sites that send visitors to deceptive pages, and Chrome then shows a full-page red warning to every visitor until a review clears it.
Hosts that receive abuse reports, or whose scanners find the script, suspend accounts first and ask questions later.
Google Ads disapproves ads that point to a compromised site, so paid traffic stops on the same day the warning starts.
Related symptoms
The same injected script that shows a pop-up today can be switched to a redirect, a fake browser-update page or a fake CAPTCHA tomorrow, because the payload is chosen on the attacker’s server, not on yours. If the symptom changes while you are investigating, it is the same infection.
Common questions
Because the script is written to avoid you. Common rules are: never show to logged-in users, show once per visitor per day using a cookie, show only on mobile, or show only to visitors whose referrer is a search engine. Test from a private window on a clean phone, arriving from a Google search, and wait between attempts.
Yes, and it is worth ruling out first. If the pop-ups also appear on unrelated websites, or only in one browser, the cause is a browser extension or notification permission on that device, not your site. Check from a different device on a different network.
It may remove the script if the script is in a file and matches a known signature. Database injections, hijacked snippets and compromised third-party scripts are often missed, and no plugin removes the backdoor or stolen password that let the script in. That is why pop-ups often return after a plugin reports the site clean.
Something is still writing it: a backdoor file, a scheduled task, a rogue administrator, or a plugin that is still vulnerable. The pop-up is the symptom; finding the writer is the actual fix.
If visitors are being sent to scams or downloads, putting the site into maintenance mode or behind a password while you work protects them and your reputation with Google. If the pop-up is an advert only, you can usually investigate first, but do not leave it for days.
A single-site cleanup here is a fixed fee from $120 to $500, agreed before work starts, with a reply the same business day and most sites clean within 24–48 hours of access. The fee covers finding the way in and the backdoors, not only the visible script.
Choose the response path
One site with pop-ups now
Best when visitors are seeing pop-ups, ads or notification prompts today and you want them gone without breaking the site. Fixed fee from $120, a reply the same business day, and a written record of what was found.
After the cleanup
Best for business sites that cannot afford to find out from a customer again: updates, file and database change monitoring, and a named person to call. From $75 per site per month.