-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[LatestPosts] Fixes the excerpt length #20313
Conversation
Size Change: +6.24 kB (0%) Total Size: 865 kB
ℹ️ View Unchanged
|
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.
Shouldn't we apply the trimming according to the defined length to this line instead?
$trimmed_excerpt = get_the_excerpt( $post );
As discussed in the design channel on Slack we should stick to the following process:
This behavior is both consistent to how WordPress currently handles excerpts and also with what a user would expect from the system. There are two new issues that spawn from this:
|
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.
Hi @draganescu, I think the reason we were using a filter was to make sure manual excerpts are respected but in my tests, while this PR makes the excerpts not trimmed on the frontend, it seems manual excerpts are not respected on the editor.
I created a post with the following manual except: aaaaa1 bbbb2 cccc3 dddd4 eeee5 ffff6 gggg7 hhhhh8 iiiiii9 jjjjjj10 llllll11 mmmmmm12 nnnnnn13
, and published it.
I created another post with the latest posts block with except length of 10. The excerpt displayed as aaaaa1 bbbb2 cccc3 dddd4 eeee5 ffff6 gggg7 hhhhh8 iiiiii9 jjjjjj10 ... Read more
instead of showing the complete excerpt I wrote on the editor.
…e remove and is not affecting theme set length
@aduth regarding the use of anonymous functions as filters I tested the implementation of filtering excerpt_length in the latest post block with an anonymous function assigned to a variable:
then removing it with
then in
and these posts had their excerpt stuck to the length set by the block latest posts contained in the single post. So it means we can't do it any other way but with named functions so that we can remove them after we render the blocks. Using a global reference and a named function the same test reverts OK to the default WP excerpt length. |
@jorgefilipecosta there is another PR that fixes the block's edit to respect manual excerpts: #20432 |
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.
LGTM 👍
* adds a filter that sets the excerpt length to what was set in the editor * adds named function as excerpt filter and removes after use * adds PHP doc to the new filter callback and global variable * default to using an anonymous function since it appears that it can be remove and is not affecting theme set length * revert to named function for excerpt length filter * proper function names for Guternberg namespace * lower default priority for the latest posts excerpt length filter
* adds a filter that sets the excerpt length to what was set in the editor * adds named function as excerpt filter and removes after use * adds PHP doc to the new filter callback and global variable * default to using an anonymous function since it appears that it can be remove and is not affecting theme set length * revert to named function for excerpt length filter * proper function names for Guternberg namespace * lower default priority for the latest posts excerpt length filter
Just because customers flooded my e-mail and didn't know this was design by choice: is there any way to also trim manual excerpts in the block or do i have to edit the core files?
I can verify at least 12 of my customers do not agree after updating to 5.4. All of them expected the manual excerpt to be trimmed as well. |
Howdy @raQai and thank you for the feedback! This change to the LatestPosts block may have broken some fixed layouts, is this your customer's case as well? It is important why would a manual excerpt be trimmed. How would this benefit your customers? |
I was finally able to check all the sites "affected" by this. Some of them used fixed layouts, some have been wondering because they used the "read more" link in form of a button to give better feedback to site visitors showing them "hey, you can continue reading here." The main issue for most of them relates to the latter. As far as I can tell, there is no direct hook to append this button, is it? |
Just to make sure I understand:
|
@draganescu correct. A simple checkbox to allow to "always display read more link" would solve this issue. That's what I am currently working on but since I never worked on custom gutenberg blocks before, I first have to dig into the documentation :) |
I'll open an issue for this. Thank you! The problem is some themes add their own link and you end up with two :) so we need a way to know that the theme adds its own read more link. |
Description
Closes #20311
It is a bug introduced by #19669
How has this been tested?
Tested locally by:
Types of changes
Introduces an excerpt_length filter in the
LatestPosts
block.