How to find and remove double spaces in WordPress posts

Double spaces are the most common small mistake in WordPress content. They come from old typing habits, from text pasted out of Word, Google Docs or PDFs, and from content migrated between systems. On a site with hundreds of posts, finding them by eye is hopeless. This guide shows where they come from, when they are actually visible, and three ways to clean them up — from a SQL query to a plugin.

Where double spaces come from

  • Typing habits. Many people learned to type two spaces after a period, and some still do.
  • Copy and paste. Word, Google Docs and PDFs often carry extra spaces from justified text, tabs converted to spaces or manual alignment.
  • Edits. Deleting a word in the middle of a sentence often leaves the spaces on both sides.
  • Imports and migrations. Content moved from another CMS, a page builder or a spreadsheet frequently brings stray whitespace along.

Do readers even see them?

Sometimes not — and that is why they pile up unnoticed. In normal HTML, a browser collapses a run of ordinary spaces into one when it renders the page. But double spaces still show up in many places:

  • In the editor. The block editor keeps your spaces as typed, and editors typing several spaces in a row often get a non-breaking space ( ) inserted, which is never collapsed.
  • In blocks and themes that preserve whitespace (CSS white-space: pre-wrap), such as the Verse block.
  • Outside the browser: RSS readers, e-mail newsletters built from your posts, plain-text excerpts, mobile apps and headless front ends that read the REST API.
  • When content is copied into another document, a social post or a translation tool.

Clean text is also simply easier to search, compare and maintain.

Method 1: find them with SQL

If you have database access (phpMyAdmin, Adminer or wp db query), this lists published posts and pages that contain two spaces in a row. Replace wp_ with your table prefix.

SELECT ID, post_type, post_title
FROM wp_posts
WHERE post_status = 'publish'
  AND post_type IN ('post', 'page')
  AND post_content LIKE '%  %';

Expect a long list. The query also matches indentation inside HTML, block markup and code samples, which is harmless. On MySQL 8 and MariaDB 10.0.5+ you can narrow it to spaces between two visible characters:

SELECT ID, post_type, post_title
FROM wp_posts
WHERE post_status = 'publish'
  AND post_type IN ('post', 'page')
  AND post_content REGEXP '[^[:space:]>]  +[^[:space:]<]';

This is still approximate: it cannot tell text from a code block or a shortcode attribute. Use it to find posts, then fix them in the editor — or move on to the next methods.

Non-breaking spaces are stored as &nbsp; or as the UTF-8 character U+00A0, so LIKE '% %' does not catch them. Search for '%&nbsp; %' separately if you suspect them. Not every non-breaking space is a mistake — they are often used on purpose, for example in French typography or to keep "10 km" together.

Method 2: replace them with WP-CLI

wp search-replace can replace every double space in post content. Always run a backup and a dry run first:

wp db export before-cleanup.sql
wp search-replace '  ' ' ' wp_posts --include-columns=post_content --dry-run

If the numbers look right, run it again without --dry-run. Three spaces become two after one pass, so repeat until it reports 0 replacements.

This is fast, but it is a blunt tool:

  • It also changes spaces inside <pre> and code blocks, where indentation matters, and inside shortcode attributes and HTML.
  • It changes drafts, revisions and every post type in that column unless you narrow it down.
  • It creates no revisions and leaves no record of what changed. The only undo is restoring the database backup — which also reverts every other change made since.
  • You never see what it is about to change.

The plugin Better Search Replace does the same from the dashboard, with the same caveats.

Method 3: find and fix them with a plugin

Content Polisher was built for exactly this. It scans posts, pages and custom post types and reports each double space with a Before / After preview:

Double spaces Safe fix
Before
Tram 28 is charming  and always full.
After
Tram 28 is charming and always full.
  • Only ordinary spaces between two visible characters are reported. Indentation in the HTML source, line breaks and non-breaking spaces are left as they are.
  • Code is never touched: pre, code, code blocks, custom HTML blocks and code shortcodes are skipped, and links, attributes and block markup keep every byte.
  • Fix one issue, or every safe issue of a post in one click. Each fix is saved as a normal WordPress revision and listed on the History page, where it can be undone — without overwriting later edits.

In the same scan it also finds spaces before punctuation, missing spaces after punctuation, wrong dashes and empty paragraphs. See the full list of rules.

One space or two after a period?

One. Current style guides — The Chicago Manual of Style, the APA Publication Manual (7th edition) and most publishers — use a single space after a period. Two spaces were a habit from monospaced typewriter fonts and are not needed with proportional fonts.