Skip to content

Latest Posts block: Check priority of excerpt_length filter #33027

Open
@BinaryMoon

Description

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.

add_filter( 'excerpt_length', 'block_core_latest_posts_get_excerpt_length', 20 );

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.

Metadata

Assignees

No one assigned

    Labels

    Needs Technical FeedbackNeeds testing from a developer perspective.[Block] Latest PostsAffects the Latest Posts Block[Feature] ThemesQuestions or issues with incorporating or styling blocks in a theme.[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions