-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Latest Posts block: Check priority of excerpt_length filter #33027
Comments
I also noticed this while testing WordPress/wordpress-develop#5441 (comment) I've tested using Before
After
|
@ramonjd behaviour is different based on how the excerpt was acquired, what would be useful is a mapping of all the ways excerpts can be shown, and when/how/if they're truncated, making the point to distinguish between user defined excerpts and auto-generated excerpts. Perhaps a table? |
There's a few gaps off the top of my head I'm unsure of their nuances, and I'm sure there are use cases I did not mention in the table, but it's a start |
Thanks a lot for this @tomjn! I find most of my confusion is reduced by bumping the priority of the filter to The only discrepancy I find is in the editor, which fetches the rendered excerpt from the post object ( The discrepancy is most obvious when moving from a low word count to a higher one. Because the excerpt with a lower word count has been saved to the database, the editor cannot render the excerpt preview with a higher word count because those words are not available. Only after save are my changes reflected. 2023-10-11.12.31.00.mp4 |
hmmm that's unusual and looks like a separate bug with the latest posts block, can you create an issue to track that? Note that this is a new place I did not expect so it does not appear in the table I posted earlier. Be sure to include the copy pasted blocks when you open the issue so that people can copy paste it into their editor to reproduce the problem. |
It appears to be a side effect of bumping the priority of the I think the post object (in the editor) is returning the I'll keep an ear out on this issue and do a follow up issue if we come up with a fix. |
I've looked at the code and managed to update the table further:
Note that it's expected that user generated excerpts aka manual are not influenced by the It's as accurate as the current code in the WP and GB github that I can follow In this case the latest posts block is a bit redundant considering we have query blocks, I'd recommend using that in conjunction with a post excerpt block. The global variable is a bit of a curveball but can be sidestepped with the query block. This also means that expected behaviour can be returned to both the excerpt block and the latest posts block if your excerpt length filter has a priority of 11 or higher |
This also reveals that greater compatibility might be had if this code: was changed so that instead of falling back to the hardcoded value of $filter_excerpt_length = function( $length ) use ( $attributes ) {
return isset( $attributes['wordCount'] ) ? $attributes['wordCount'] : $length;
}; It could even be questioned that Either of these would bring the excerpt block much closer to the expectations of those coming from classic themes while preserving the functionality added to the excerpt block. Importantly, the latest posts block does not use the same mechanism for setting the excerpt, and could have its global variable removed and replaced with the same filter used by the excerpt block. Resolving this issue as well. Finally, does it make sense to keep the filters using the same priority in these blocks, or should they instead use a lower priority such as |
I am not working on the excerpt. |
I agree, this is to cover the situation when the user has not made such a setting and no block attribute is set. If I were to write a user story:
Scenario 1 passes. Scenario 2 fails. Instead in the latest posts block it is hardcoded to 55. |
That is helpful, thank you. |
Hi - the excerpt length setting in the latest posts block does not get used in all themes. This seems to be a common problem in themes that change the default excerpt length.
This appears to be a because of the excerpt_length filter in the render method.
gutenberg/packages/block-library/src/latest-posts/index.php
Line 48 in 97caf7b
In the method the filter has a priority of 20, however the official WordPress docs suggest a priority of 999 which I have found referenced on a number of sites and used in many themes.
https://developer.wordpress.org/reference/hooks/excerpt_length/#more-information
I started updating my 20+ themes to use a lower priority but then realised that it's used in so many other themes that it should probably be changed in core.
You can see how many public themes use it here:
https://wpdirectory.net/search/01F9927FX53NQ7AA33DS32YK38
If you expand the top 20 results on this page you will see that about 50% use the 999 priority.
My suggestion would be to use
9999
since some people (including myself) may go even higher in child themes.The text was updated successfully, but these errors were encountered: