-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Remove HTML entities from post slug during cleaning #68813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove HTML entities from post slug during cleaning #68813
Conversation
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @APCgit. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks for contributing, @devansh016! The referenced issue has a PR (#62549) with an ongoing review process. Just FYI. |
Thanks, @Mamaduka! I’ve reviewed the other PR. My approach is slightly different, and the previous PR has been inactive for the past couple of months. |
|
Hi, @devansh016. Thanks for the PR. I've discovered that simply decoding HTML entities isn't enough. Besides HTML entities, there are many other characters that need to be handled. For example, the slug of the title However, the slug becomes In other words, as mentioned in this comment, we may need a JS function equivalent to |
The |
|
Try updating a slug that has already been published, the result is completely different. When publishing you can handle the slug through PHP, but when updating a published post there is no php filter involved and this ends up in non transformed slugs with wrong umlauts and characters just removed. Its very inconsistent. Unfortunately I didnt find a way to filter the slug myself for the default ui. I added a custom input to handle umlauts and characters properly, but that's not how it should work... |
|
@APCgit, the There are a couple of reasons the method doesn't allow filtering the return value:
|
|
Thanks for the initial proposal, @devansh016! I'm going to close this in favor of #70078. |


What?
This PR ensures that HTML entities, such as
&, are properly decoded when generating post slugs. It modifies thegetEditedPostSlugselector to decode entities in post titles before cleaning them for slug creation.Why?
The current implementation adds unnecessary HTML entities like amp to slugs when saving drafts. This behavior can cause confusion and lead to unnecessarily long or SEO-unfriendly URLs. For example, a draft title containing
&becomes/ampersand-amp-and/, but upon publishing, it correctly becomes/ampersand-and/. This PR fixes the inconsistency by decoding HTML entities before cleaning the slug.Fixes #62543
How?
Code changes are minimal and located in
packages/editor/src/store/selectors.js.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast