Non-breaking spaces after single-letter prepositions for Czech WordPress sites
Czech typography inserts a non-breaking space after single-letter Czech prepositions and conjunctions (k, s, v, z, o, u, a, i) so they never end up alone at the end of a line. It works on content, titles and ACF text/WYSIWYG fields — no need to call a custom filter in your template.
Key features
- Works on the_content, the_title, the_excerpt and ACF text/textarea/WYSIWYG fields
- Operates only on text nodes — never touches inside HTML tags, attributes, <script> or <pre>
- Idempotent — running it repeatedly never doubles up the spaces
- The `nbsp` Twig filter registers only if the site actually uses Timber (no unnecessary integration otherwise)
- A public `smrk_nbsp()` function for manual use outside the standard filters
How it works
The text is first split into HTML tags and plain text segments using balanced tag-pair parsing (not a naive regex over the whole HTML), so a non-breaking space is never inserted inside a tag or attribute.
Each text segment is then run through the regular expression `/(?<=^|\s|\()([ksvzaiou])(\s)+/iu`, which joins a single-letter preposition/conjunction at the start of a word to the following word via ` `.
An alternative to Zalomení, Čeština: zalomení řádků or Sirotci (sierotki) — with ACF integration that needs no custom filter call in your template.