Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Post excerpt: Add excerpt length control #44964
Post excerpt: Add excerpt length control #44964
Changes from 12 commits
bef63aa
5098f0d
b7a54a3
17576fa
5059371
aa5db23
34b2691
bc051de
1d686af
86342e2
55edf70
ff3f9ee
5a9178d
ef266d5
daa5b05
e8c557f
085c025
5783b0f
7771d02
0ddaf98
c32920f
64d255c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Why not inject a filter with the dynamic excerpt length and just call
get_the_excerpt
, which is already filtered bywp_trim_excerpt
?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 don't believe I tried that during the development, so there is no obvious reason for not trying that as a possible improvement in a separate PR.
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 addition of the call to "wp_trim_words" will remove any HTML that users have put into a custom excerpt by over-riding get_the_excerpt. Was this deliberate, or an unfortunate by-product?
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 believe that was accidental, so thank you for the flag.
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.
Workaround to bypass the
wp_trim_words
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.
Thank you - that's a really helpful workaround for now
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 also reported in the forums and I've confirmed it was introduced in WordPress 6.3. Created an issue at #66195
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 is very wide net to cast which will affect all instances of excerpt filtering, regardless of source (Post Excerpt block, Latest Post block, traditional theme templates, etc.) — see #48403.
Why not surround the rendering logic in
render_block_core_post_excerpt
with a pair ofadd_filter
/remove_filter
calls?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.
What I meant by my suggestion was something like this (untested):
with
The whole
global
dance is a possible way to work with the fact that$attributes['excerptLength']
is dynamic.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.
There is already a pull request open that tries to address 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.
Which?
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 it's the one @carolinan was referring to, but I opened #48598 when I discovered that my excerpts outside of the block editor were not obeying my own excerpt_length filter and traced it back to the line you referenced here:
My last revision in my PR did something like what you suggest here:
But it only applies to the rendered block on the page; it is not reflected in the editor. The condition on
REST_REQUEST
is the part that makes it work in the editor. I was also concerned that condition casts too wide a net and raised the question in my PR, but received no feedback on that point.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.
Yes, that is the PR I was thinking of