Codiffy (codiffy.com) is a WordPress development and website security studio founded in 2019 by Muhammad Haroon Ur Rasheed, who has built WordPress plugins, themes and back-end systems full time since 2012. Codiffy cleans hacked WordPress and WooCommerce sites for businesses in the United States and Canada, including sites where the spam lives only in the database.
WordPress SEO spam is text and links that a hacker saved into your database: inside post content, page builder data or settings. Deleting theme files will not remove it, because the spam is stored as content. To clean it, back up the database, search it with read-only SQL, remove only the spam, check the revisions too, and then find how the hacker got in. Skip that last part and the spam returns.
Need it fixed now? Call +1 (347) 474-0387, answered immediately, 24/7. We find and remove the spam, clean the rest of the site the same day, from $200, and you get the fixed price in writing before we start. WordPress malware removal
How to clean SEO spam from the database
- Confirm the spam and find the first date.
- Back up the database.
- Search the database with read-only SQL.
- Clean the spam carefully.
- Check revisions, options and other tables.
- Close the way in and ask Google to recrawl.
What database spam looks like
Hackers borrow your site’s authority to sell casino games, lottery numbers, pills and replica goods. The spam usually takes one of these forms:
- New spam posts among your real ones.
- Links spliced into real posts. At In Order to Succeed, a professional organizing firm, German casino spam had been spliced into real testimonial posts.
- Hidden blocks in page content, pushed off the screen with CSS or shrunk to nothing, so people do not see them but Google does.
- Scripts or links in widgets, options and header settings.
Stored content survives a theme change, a plugin reinstall and a file-only cleanup. The site often looks normal to you. At BenchmarkTitle.net, a real estate and title services site, the whole site held around 300 hidden gambling and lottery links, yet there were no redirects and no warnings.
Step 1: Confirm the spam and find the first date
Start with what Google sees, because that is where the damage shows up.
- Search Google for
site:yourdomain.com casino, and tryviagra,slot,replicaandtoto. Pages or snippets you did not write point to spam. - Open Search Console > Performance and look at Queries and Pages. Search terms unrelated to your business, or a URL you do not recognize, are the usual first clue. At In Order to Succeed, the owner saw nothing wrong. Their SEO consultant found the hack in Search Console, where one spam page had 2,402 impressions.
- Run URL Inspection and choose “View crawled page”. That is the HTML Google received, which may differ from what you see. Spam hidden from visitors shows up here.
- Open the post’s revisions. The first revision that contains the spam gives you a date for the server logs.
If you see the “This site may be hacked” label, read our guide on Google’s warning for the review process.
Step 2: Back up the database
Never edit a live database without a way back. Over SSH, export it to your home folder, outside the public web folder:
wp db export ~/db-before-spam-cleanup.sql --skip-plugins --skip-themes
Without SSH, use your host’s phpMyAdmin Export. Keep the file out of public_html, because anyone can download a dump left in the web folder, and it contains user data. Delete it when the job is done.
Step 3: Search the database with read-only SQL
A SELECT query only reads. Run these through wp db query or phpMyAdmin. Change wp_ to your table prefix (wp db prefix shows it).
Find posts with spam words:
SELECT ID, post_type, post_status, post_title FROM wp_posts WHERE post_content LIKE '%casino%' OR post_content LIKE '%slot gacor%' OR post_content LIKE '%viagra%'
Find the hiding tricks, such as links pushed off the screen or shrunk to one pixel:
SELECT ID, post_type, post_title FROM wp_posts WHERE post_content LIKE '%left: -5000%' OR post_content LIKE '%font-size: 1px%' OR post_content LIKE '%display:none%'
At BenchmarkTitle.net the hidden blocks looked like this (recreated, with the spam domains removed):
<div style="position: absolute; left: -50000000px;"> ...dozens of casino and lottery links... </div>
Find page builder data, which lives in post content or post meta:
SELECT ID, post_title FROM wp_posts WHERE post_content LIKE '%[vc_row%' AND post_content LIKE '%left: -5000%'
SELECT post_id, meta_key FROM wp_postmeta WHERE meta_value LIKE '%casino%' OR meta_value LIKE '%left: -5000%'
WPBakery stores its layouts as shortcodes such as [vc_row] inside post_content, so spam hidden in a WPBakery section sits in the column the first queries search. Its Raw HTML element can store content encoded, so a word search may miss it. Search for vc_raw_html and decode that text before you decide it is harmless.
Find settings and widgets:
SELECT option_id, option_name, LENGTH(option_value) FROM wp_options WHERE option_value LIKE '%casino%' OR option_value LIKE '%<script%'
Do not print full option values, because some are very large. Read one suspicious row at a time, and note every ID you find so you can verify after cleaning.
Step 4: Clean the spam carefully
Match the tool to the spam.
- Whole spam posts: if the post is not yours, delete it. At In Order to Succeed, 65 spam posts were removed. Over SSH:
wp post delete 123 456 --forcewith the IDs you checked. Check each title and date first, because aLIKEsearch can catch real posts. - Spam links inside real posts: open the post in the editor, switch to the code or text view, and delete only the hidden block. For many posts, use a search-replace on the exact spam block.
- Page builder sections: remove the spam row or section in the builder, and save. If the builder shows nothing odd, the spam may be in a Raw HTML element or in the post meta.
For bulk removal, use WP-CLI’s search-replace, not a raw UPDATE. It understands serialized data and will not corrupt it. Always start with a dry run:
wp search-replace '<the exact spam block>' '' wp_posts --dry-run --skip-plugins --skip-themes
The dry run reports how many replacements it would make and changes nothing. Run it for real only when the count matches what you expect. A pattern that is too short can erase real content. If the spam varies from post to post, handle it by hand or hand it to a developer.
The method Codiffy used at BenchmarkTitle.net is a good model: make a backup table first, run controlled cleanup queries that remove only the malicious containers and hidden links, then run the detection queries again. They returned zero results. Read the BenchmarkTitle.net SEO spam case.
Step 5: Check revisions, options and other tables
Clean content can come back. WordPress keeps revisions of posts, and a revision still holds the spam.
SELECT ID, post_parent, post_date FROM wp_posts WHERE post_type = 'revision' AND post_content LIKE '%casino%'
A revision with spam can be restored by mistake. Delete the spam revisions after you have cleaned the live post. Also check:
- Posts with the status
trashordraft, which a hacker can publish later. wp_optionsfor widget text, custom HTML widgets and header or footer script settings.wp_usersand the capabilities inwp_usermeta, for administrators you did not create.
Then run your detection queries again. Every one should return zero rows.
Step 6: Close the way in and ask Google to recrawl
Spam in the database is the result, not the cause. At In Order to Succeed, a backdoor was uploaded through the WP File Manager plugin. The host restored a 30-day-old backup and a scan came back clean, but the way in was still open. PHP also went from 7.3 to 8.3. At BenchmarkTitle.net, a compromised Hello Dolly plugin kept reinfecting the site, and the spam returned about four months after the first cleanup because the follow-up steps (new passwords, new keys, updates, a newer PHP version) were skipped.
- Reset every password and the keys in
wp-config.php. - Check for administrators you did not create.
- Remove unused plugins, especially file managers and code snippet plugins, and update the rest.
- Look for hidden plugins and backdoor files. See our guide on plugins hidden from the WordPress plugins list.
- Make deleted spam pages return 404, then use URL Inspection to request indexing for your key pages. Do not block spam URLs in robots.txt.
Codiffy’s order on every hacked site is the same: visible symptoms, error logs, recently changed files and added code, database search, scans with Guardian Shield Lite, forensics in the server terminal (when, how, which scripts), and last, close the way in. For the full process, read how to fix a hacked WordPress site.
When to call a developer
Call for help if:
- You do not use SSH, SQL or WP-CLI, or you are not sure which rows are spam.
- The spam is inside a page builder and you cannot see it in the editor.
- The spam came back after you cleaned it.
- Google shows a hacked-site warning, or you run an online store.
Codiffy cleans hacked WordPress and WooCommerce sites 24/7, from $200, usually $200 to $400. If the malware returns, we clean it again free. Call +1 (347) 474-0387 or email haroon@codiffy.com. See the malware removal service
Frequently asked questions
Why does the spam come back after I delete it?
Usually because you cleaned the result and left the cause. A backdoor, hidden administrator, compromised plugin or leftover revision can put it back.
Is a SELECT query safe to run?
Yes. It only reads data. The risk starts with UPDATE, DELETE and search-replace, so back up first and use a dry run.
How do I know the spam is gone?
Re-run your detection queries and get zero rows, check the crawled page in URL Inspection, and watch Search Console for new spam queries over the next weeks.
Will restoring a backup fix it?
Only if the backup is older than the first spam and you close the entry point as well. A clean scan is not proof.
About the author
Muhammad Haroon Ur Rasheed founded Codiffy in 2019. He has been a full-time WordPress and back-end developer since 2012 and has fixed broken, slow and hacked WordPress and WooCommerce sites for businesses across the United States and Canada. Codiffy works from Rawalpindi, Pakistan, in US and Canadian business hours.

