WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#17190 closed defect (bug) (duplicate)

excerpt_length filter does not work

Reported by: pavelevap Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1.1
Component: Formatting Keywords: close
Focuses: Cc:

Description

Fresh install of WP 3.1.1, Twenty Ten.

Edit file functions.php - change function twentyten_excerpt_length() to return 10 words (instead of 40).
Add some random sentences to excerpt field in any post.
Excerpt is shown on website in full length (not trimmed to 10 words).

Same problem for latest 3.2 trunk.

Some other reports in forum: http://wordpress.org/support/topic/excerpt-length-doesnt-work

Change History (3)

comment:1 sivel3 years ago

  • Keywords close reporter-feedback added

The excerpt_length filter is not used for limiting the length of manually created excerpts. It is however used for limiting the length of automatically generated excerpts from the content when no manual excerpt was written.

I am assuming you are trying to limit the length of a manually created excerpt and not the automatically generated excerpts.

comment:2 pavelevap3 years ago

Yes, sorry for bothering you, I did not realize that it does not work for manually created excerpts. Is there any other function to do it? Or should I get excerpt and trim it with wp_trim_excerpt() or with my own function? But in this case, it will be needed to change also theme.

All I wanted to achieve was trimming excerpts (automatically or manually created) without editing theme (using the_excerpt() function) but only with the help of external plugin?

But you can close this ticket, I guess. Or maybe excerpt_lenght filter should also work for manual excerpts with any parameter (suggestion).

comment:3 SergeyBiryukov3 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Currently wp_trim_excerpt() only handles automatically generated excerpts.

Not exactly a duplicate, but it should be solved by #16372.

As for making excerpt_length filter work for manual excerpts, I believe esmi's reply on the forum thread linked above makes sense:

I'd guess that the assumption was, if you manually added an excerpt, you'd want it all to be shown. The filter only runs on the auto-generated excerpt.

Note: See TracTickets for help on using tickets.