[wp-trac] [WordPress Trac] #64552: wp_trim_words fails with certain charsets in the Excerpt
WordPress Trac
noreply at wordpress.org
Sun Jan 25 17:06:03 UTC 2026
#64552: wp_trim_words fails with certain charsets in the Excerpt
--------------------------+---------------------------------------
Reporter: SirLouen | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 7.0
Component: Formatting | Version: 3.0
Severity: normal | Keywords: needs-patch has-test-info
Focuses: |
--------------------------+---------------------------------------
== Bug Report
Following the [https://github.com/WordPress/gutenberg/pull/74925 GB74925]
we have noticed that the excerpts were not being adapted accordingly in
the Editor. It was also noticed that the current regex trim was not
applying for certain more edge character types of cases like
=== Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 144.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Three 1.6
- MU Plugins: None activated
- Plugins:
* Gutenberg 22.4.1
=== Testing Instructions
1. Ideally use the 2023 theme
2. Create a new post and add the following excerpt:
{{{
Fabio vel iudice vincam, sunt in culpa qui officia.
Inmensae subtilitatis, obscuris et malesuada fames.
Ambitioni dedisse scripsisse iudicaretur.
Nec dubitamus multa iter quae et nos invenerat.
Petierunt uti sibi concilium totius Galliae in diem certam
indicere.
}}}
3. Go to Appearance > Editor
4. Click on the canvas
5. Select the excerpt of the newly created Post
6. Adjust the Excerpt Max Number of Words (you need Gutenberg trunk to
test this; if you don't use trunk, it will not work either in the Editor).
7. Set, for example, 30 words, and Save
8. Go to the front end.
9. 🐞 The number of words is not the same as in the editor.
=== Expected Behaviour
- The number of words of the excerpt should be the same in the Editor and
in the front end.
=== Additional Information
Apparently, it appears that the `wp_trim_words` is not trimming all types
of spacing characters accordingly; hence, the word count is inconsistent.
@t-hamano proposed that the `/[\n\r\t ]+/` must be fixed for this purpose.
It appears that this was first introduced in [13942]/#10376
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64552>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list