Czech typography

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 `&nbsp;`.

Compared to alternatives

An alternative to Zalomení, Čeština: zalomení řádků or Sirotci (sierotki) — with ACF integration that needs no custom filter call in your template.

Frequently asked questions

Does it work in an ACF WYSIWYG field I output directly, without a filter?
Yes — the module also hooks into acf/format_value for text, textarea and WYSIWYG fields, so you never need to call the function manually.
Could this break the HTML in my content?
No, the filter works exclusively on text nodes outside tags and attributes.
Does it support Timber/Twig templates?
Yes — if the site uses Timber, an additional `nbsp` Twig filter is registered automatically.