Skip to content

Excerpt limit is overruled #48403

@jeffreyvr

Description

@jeffreyvr

Description

Since Gutenberg 15.2.0, the set excerpt length limit is not always respected.

When you have a Homepage set (Settings -> Reading), and have a custom query on front-page.php, it does no longer limit the length.

This bare bones theme reproduces the issue:

https://github.com/jeffreyvr/gutenberg-excerpt-limit-bug

Step-by-step reproduction instructions

  1. Create a page called 'Home' and setting it as the 'Homepage' in Settings -> Reading.

  2. Create a posts with text exceeding the excerpt limit. Example:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer dictum porttitor gravida. Nulla efficitur, enim in ultrices dignissim, augue justo efficitur tellus, et condimentum enim magna id erat. Nam a consectetur magna, dapibus gravida tortor. Nulla quis dapibus massa. Phasellus mattis sem vitae maximus congue. Praesent pharetra vulputate quam a sodales. Quisque in risus turpis. Maecenas eu molestie arcu. Sed sed finibus magna. Integer in rhoncus velit, in luctus turpis. Nam volutpat lorem vel purus ultrices bibendum non vel enim. Duis sem nibh, ultrices quis pulvinar vitae, congue vel lorem. Praesent suscipit risus quis lacinia consectetur. Etiam ornare scelerisque convallis. Aenean id nibh eget massa aliquam laoreet quis non ex. Aliquam non tortor et neque placerat tempus eu non sapien.

Nulla sodales sapien ac nisl luctus, nec finibus odio aliquet. Nunc massa neque, ultricies eu elementum non, vehicula at nulla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Donec dapibus enim id varius placerat. Ut vel orci bibendum sem viverra sollicitudin. Sed ullamcorper eros arcu, vehicula pulvinar dui posuere eget. Cras ut nisl sit amet sapien tristique eleifend at vel sapien. Quisque congue, odio vel vestibulum interdum, ex nisl malesuada mauris, ac hendrerit nulla nisi et sem. Nam id risus vestibulum, congue ante in, ornare justo. Vestibulum consequat justo ac eros faucibus, at interdum est placerat.
  1. The front-page.php should contain a custom query to display recent posts.
<?php
    $custom_query = new WP_Query( array(
        'post_type' => 'post',
        'posts_per_page' => 3,
        'orderby' => 'date',
        'order' => 'DESC',
    ) );
?>

<?php if ( $custom_query->have_posts() ) : ?>
    <?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>

        <div>
            <h2><?php the_title(); ?></h2>

            <div><?php the_excerpt(); ?></div>
        </div>

    <?php endwhile; ?>

<?php endif; ?>
  1. In functions.php limit the excerpt length:
function example_site_custom_excerpt_length( $length ) {
    return 20;
}

add_filter( 'excerpt_length', 'example_site_custom_excerpt_length', 999 );

Screenshots, screen recording, code snippet

Screen.Recording.2023-02-24.at.11.31.36.mov

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] Post ExcerptAffects the Post Excerpt Block[Type] BugAn existing feature does not function as intended[Type] RegressionRelated to a regression in the latest release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions