Skip to content
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

Fix Post Excerpt length when there's no excerpt and post content is used instead #61888

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

kmanijak
Copy link
Contributor

@kmanijak kmanijak commented May 23, 2024

What?

Post Excerpt allows users to set the excerpt length in Editor (10 - 100 words). If a post has no excerpt, the post content is taken as a fallback. Post Content is truncated internally before reaching the Excerpt block to 55 words with default WordPress ellipsis: […] instead of Excerpts ellipsis .

Check the screenshot below, the excerpt (pink background) length is set to 100 words:

Before After
image image

Why?

In get_post_excerpt we read:

If this function is used outside The Loop and the post doesn’t have a custom excerpt, this function will use wp_trim_excerpt() to generate an excerpt.

then in wp_trim_excerpt:

Returns a maximum of 55 words with an ellipsis appended if necessary.
The 55-word limit can be modified by plugins/themes using the ‘excerpt_length’ filter.

How?

Before calling get_post_excerpt we call a excerpt_length filter and pass $excerpt_length attribute if set.

Testing Instructions

  1. Create new post
  2. Insert content that is longer than 100 words
Example content Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sed nibh blandit, sodales enim aliquet, ultricies ligula. Praesent enim lectus, gravida a sapien eget, venenatis tempor ligula. Etiam cursus, nisl id molestie rutrum, ex velit volutpat arcu, at blandit quam lectus ut urna. Sed at venenatis turpis, convallis laoreet ante. Nulla lobortis odio non est eleifend, eu vulputate arcu pharetra. Pellentesque porta ante non mauris rutrum consectetur. Quisque nulla neque, vestibulum sed consectetur eget, pellentesque quis felis. Nullam maximus felis neque, a efficitur velit venenatis vitae. Praesent elit sem, bibendum id malesuada sit amet, tristique non turpis. Vivamus varius venenatis sem auctor semper. Cras imperdiet risus diam, sit amet tincidunt dui dictum posuere.

Duis ut tellus fermentum arcu efficitur posuere. Sed tincidunt, nulla a porttitor sagittis, felis felis condimentum felis, ut bibendum augue lacus eu orci. Vestibulum consequat condimentum viverra. Duis pharetra turpis vel varius malesuada. Quisque id velit id.

  1. Insert Excerpt block
  2. Set MAX NUMBER OF WORDS to 100
  3. Save and go to frontend
  4. Expected: Excerpt is indeed 100 words long, not 55 (no need to count words, asses the "volume" of the text based on below screenshots 🙌 )

Testing Instructions for Keyboard

Screenshots or screencast

Before After
image image

@kmanijak kmanijak requested a review from ajitbohra as a code owner May 23, 2024 06:53
Copy link

github-actions bot commented May 23, 2024

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core.
  • Labels found: [Block] Post Excerpt.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copy link

github-actions bot commented May 23, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: kmanijak <karolmanijak@git.wordpress.org>
Co-authored-by: skorasaurus <skorasaurus@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@skorasaurus skorasaurus added the [Block] Post Excerpt Affects the Post Excerpt Block label May 30, 2024
@skorasaurus
Copy link
Member

skorasaurus commented May 30, 2024

Hi,

Thanks for contributing; I don't have enough time to review at the moment but I do recall that excerpts have been an issue for sometime with multiple efforts to fix it; see #48598 (comment) and possibly #53570 and #49612 as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Excerpt Affects the Post Excerpt Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants