How to fix spaces before commas and periods in WordPress

Three days , twenty euros a day . A space before a comma or period is one of the most common small mistakes in web content, and one of the most visible: on a narrow screen the browser may wrap the line right before the comma, leaving it alone at the start of the next line. This guide covers where these spaces come from, how to find them, and when they are not a mistake at all.

Where they come from

  • Edits. Delete the last word before a comma and the space before it stays behind: We visited Lisbon (and Porto) , then…
  • Pasted text from documents, PDFs and e-mails, where spacing was used for layout.
  • Writers used to French, where a space before ; : ! ? is correct — and sometimes gets applied to commas and periods too.
  • Generated text from imports, spreadsheets or templates that join fields with spaces: {city} , {country}.

Why it matters

Unlike double spaces, a space before punctuation is never collapsed by the browser. It is visible on every page, in search results snippets and in social previews, and it allows a line break before the mark — the reason commas and question marks sometimes appear at the start of a line on phones.

How to find them

A quick database check lists posts with a space before a comma or period (replace wp_ with your table prefix; MySQL 8 or MariaDB):

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

Expect false positives: the pattern also matches code samples, version numbers in text like v 2.0 and markup. It is a way to see the size of the problem, not a safe input for search-replace — a blanket replace of " ," with "," also changes code, CSV examples and French text.

The French exception

In French, a space before ; : ! ? is required — Vraiment ? is correct, Vraiment? is not. Any tool that "fixes" spaces before punctuation on a French site breaks correct text. Commas and periods have no space in French either. More in French typography in WordPress.

Fixing them with Content Polisher

Content Polisher reports spaces before , . ; : ! ? as a safe fix with a Before / After preview:

Space before punctuation Safe fix
Before
Three days , twenty euros a day
After
Three days, twenty euros a day
  • Each post is checked in its own language: in French posts the space before ; : ! ? is kept, and a missing one is added.
  • Ellipses, emoticons, URLs, numbers and code are left alone; only the text between tags is changed.
  • Fix one issue, a whole post, or — with Pro — every safe issue on the site. Everything can be undone from History.