Skip to content

wp_trim_words - ensure word separation around br tags#11352

Open
Addison-Stavlo wants to merge 1 commit intoWordPress:trunkfrom
Addison-Stavlo:fix/br-spacing-in-excerpts
Open

wp_trim_words - ensure word separation around br tags#11352
Addison-Stavlo wants to merge 1 commit intoWordPress:trunkfrom
Addison-Stavlo:fix/br-spacing-in-excerpts

Conversation

@Addison-Stavlo
Copy link
Copy Markdown

@Addison-Stavlo Addison-Stavlo commented Mar 25, 2026

Ensures words around br tags are not concatenated together during wp_trim_words by replacing br tags with a space. This is done just before all tags are stripped and will ensure the words are actually separated when the $words_array is generated.

These br tags are common in the core block editor as they can appear in paragraph blocks (shft+enter for spacing), verse blocks, and likely more. For content written in forms similar to that of poetry or song lyrics, excerpts generated from the content stick words together. e.g. "Line one
line two" becomes "line oneline two" - this PR aims to resolve this problem at the source in trim words.

Trac ticket: https://core.trac.wordpress.org/ticket/64944

Use of AI Tools

AI assistance: Yes
Tool(s): Cursor
Model(s): Composer 2
Used for: assistance with initial code investigation, assistance with generating regex pattern, initial test suggestions, and general writing directed by me. Placement of and suggested fix made by me, test reviewed and edited by me.

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Testing

  • Run this branch on WP Playground.
  • Create a new post using a paragraph of verse block. For the verse block, standard "enter" to add new lines will repro the issue. For the paragraph block, "shft + enter" to create new lines within the block.
    • You can verify the br tags are separating the lines in these blocks by toggling the code editor setting.
  • Do not create a custom excerpt.
  • Publish the post.
  • Run get_the_excerpt for the post.
  • Verify that there are no spaces between the last words of one line and first words of the next. (on trunk, there will be words joined together as described in the examples).

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Addison-Stavlo.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant