Make WordPress Core

Opened 17 months ago

Last modified 16 months ago

#59348 new defect (bug)

Excerpt block length is not full customizable any more

Reported by: frzsombor's profile frzsombor Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

Since the latest changes in /src/wp-includes/blocks/post-excerpt.php now the excerpt length is not fully customizable any more. The problem is that previously $excerpt = get_the_excerpt(); was used, which was filterable with get_the_excerpt, but now this excerpt is just getting forcefully trimmed by wp_trim_words based on the excerptLength option. Which is: a) A number forced to be between 10-100 b) now can not be changed or overwritted with custom code in any way.

If I want to display the excerpt of a post on the post's page, now there is no way to correctly display an excerpt that is longer than 100 words. I think this is a loss in features and a bad practice to limit the excerpt's usage in this way. At least allow $excerpt_length = $attributes['excerptLength']; to be modified with the already existing excerpt_length filter.

Mentioned change:
https://core.trac.wordpress.org/changeset?sfp_email=&sfph_mail=&reponame=&new=56065%40trunk%2Fsrc%2Fwp-includes%2Fblocks%2Fpost-excerpt.php&old=55246%40trunk%2Fsrc%2Fwp-includes%2Fblocks%2Fpost-excerpt.php

Change History (2)

#2 @frzsombor
17 months ago

Update:
I just found a way to edit default block settings with "Block Hooks" (block filters), for example:

function filter_metadata_registration( $metadata ) {
    if ($metadata['name'] === 'core/post-excerpt') {
        $metadata['attributes']['excerptLength'] = 40; //ANY NUMBER
    }
    return $metadata;
};
add_filter( 'block_type_metadata', 'filter_metadata_registration' );

However, strangely enough, this code makes the "excerptLength" completely disappear from the attributes (when printed out in render_block_core_post_excerpt of post-excerpt.php) making the original

array (size=2)
  'showMoreOnNewLine' => boolean true
  'excerptLength' => int 55

to be

array (size=1)
  'showMoreOnNewLine' => boolean true

Which is cool for me, because at least I get "unlimited excerpts" but this is either a bug or I'm missing something, so I'm opening a ticket on this too.

Version 0, edited 17 months ago by frzsombor (next)
Note: See TracTickets for help on using tickets.