-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Post Excerpt Block: Fix length limits for both Editor and Front and fix ellipsis consistency. #74140
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
base: trunk
Are you sure you want to change the base?
Post Excerpt Block: Fix length limits for both Editor and Front and fix ellipsis consistency. #74140
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 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 your first Pull Request and for helping build the future of Gutenberg and WordPress, @ItsYash1421! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test Report
Description
❌ This report can't validate that the indicated patch works as expected.
Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.3
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 143.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Three 1.6
- MU Plugins: None activated
- Plugins:
- Gutenberg 22.3.0
- Test Reports 1.2.1
Testing Instructions
- Using TT3 theme
- Added the Read more
- 🐞 The ellipsis only appears on the editor, not in the frontend
Actual Results
- ❌ Issue resolved with patch.
Supplemental Artifacts
SirLouen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ItsYash1421 you have not changed anything in the last 3 commits, only added and removed package.json, and changed the unit tests.
The changes are working fine here is screenshots after applying changes. |
|
@ItsYash1421 please use this playground instance to test: 74140.mp4 |
its working their too.
|
|
@ItsYash1421 we are doing something differently for sure. Can you share a screencast of the whole process? |
1221.mov |
|
I think it was not working with Number of words more than 55 |
I was not touching the number of words, so yes, probably. This must work for all numbers. |
i fixed it in latest commit please check |
| * Otherwise, the read more link filter from the theme is not removed. | ||
| */ | ||
| add_filter( 'excerpt_more', $filter_excerpt_more ); | ||
| $filter_excerpt_length = static function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the best fix. I have a hunch that there is probably something intrinsecal, maybe in Core. More research is required here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that WordPress Core's get_the_excerpt() applies the excerpt_length filter (default 55 words) during frontend rendering. The editor avoids this by getting the raw excerpt via REST API (which already has the filter override).
My fix extends this same pattern to frontend rendering, ensuring consistency between editor and frontend for excerpt lengths 56-100 words. This mirrors the existing approach rather than introducing a new pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried over 55 and its not showing in the ellipsis frontend.
Anyway I don't like the filter solution. I will give it a thought on how to improve it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
bb8668a to
e957b92
Compare
e957b92 to
0bfbe09
Compare
0bfbe09 to
d84df43
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reviewed this, and now it looks legit.
Here are the changes (this is easily visible in Twenty Twenty Three theme)
Currently the excerpts display can only handle correctly the manual excerpts. But if we are using the automatic excerpts, there are inconsistencies between the editor and the front end.
The solution is to extend a little the current flow to have a unified mechanism to display for both the automatic and manual excerpt the limit of the RangeControl (100 words).
Using this url for testing (with 2023 theme):
/wp-admin/site-editor.php?p=%2Fwp_template%2Ftwentytwentythree%2F%2Findex&canvas=edit
Adding or not adding Read More as pointed out in #74133 should be irrelevant; in any case, with and without Read More and for automatic and manual excerpts, it should behave identically: if there are more words available than the maximum selected in the RangeControl the ellipsis should appear for both editor and frontend.
Editor:
Frontend
cc @ntsekouras I noticed you worked in the render excerpt part, could you do a final second review to double check everything is in order now?
| if ( is_admin() ) { | ||
| add_filter( 'excerpt_length', 'block_core_post_excerpt_excerpt_length', PHP_INT_MAX ); | ||
| } | ||
| add_action( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this change affects anything. Do you know why we had defined( 'REST_REQUEST' ) && REST_REQUEST ) (essentially wp_is_serving_rest_request)?
It seems this change to have the same effect, but I might be missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was proposed for #48654 and @mcsf got some concerns that were not addressed in #44964. The problem is that he is not addressing either the problem of the frontend, the ellipsis variations (difference between ... and [...] and the scenario of the automatic excerpts).
The problem is that there was no unified logic.
Now the logic is unified for all 3 cases
- For admin, it will called inmediately during
init - For REST API Requests (in this case in for the editor) its called via
rest_api_init. - Frontend, on ìnit`
Before it was calling during init but REST_REQUEST was not defined yet. So for the manual excerpts it worked well, but for the automatic excerpts that were built through the API, it was not building the right excerpt. In fact by default in Core, manual excerpts should be shown completely, and what it's handled is the lenght of the automatic excerpts (not the other way around as it's being done here).
| * wp_trim_words is used instead. | ||
| * | ||
| * To ensure the block's excerptLength setting works correctly for auto-generated | ||
| * excerpts, we temporarily override excerpt_length to 100 (the max block setting) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be to 101, no? A small rewording here to either mention 101 and that 100 is the max setting or something like override to x + 1 of the maximum setting.
ntsekouras
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a small docs comment but this seems to be fine. Something related that could be handled either here or separately, is a small inconsistency between editor and front-end for custom excerpts.
I tested a post with a big custom excerpt (more than 100 words) and in the editor we show one more word than the front-end.





Fixes #74133
What?
Closes #74133
Adds the missing ellipsis (…) to the Post Excerpt block on the frontend when the excerpt is trimmed and a read more link is present.
Why?
The ellipsis was correctly displayed in the editor but missing on the frontend, creating an inconsistent user experience. When users add a "read more" link to a trimmed excerpt, the ellipsis should appear to indicate the content continues, matching the editor preview.
How?
wp_trim_words()to prevent it from automatically adding its own ellipsis…when the excerpt is trimmed and displayed inline with the read more linkTesting Instructions
Testing Instructions for Keyboard