• Resolved sfjwebsfj

    (@sfjwebsfj)


    I have almost 2000 posts, each with manually entered excerpts, most of which are more than 100 words. My current theme is kind of old and I would like to use Twenty Twenty-Four. The new Excerpt Block introduced an apparently arbitrary max-limit of 100 words, and even though it isn’t supposed to (as I understand it), it IS cutting the manual excerpts down to 100 words. 100 words isn’t even a medium length paragraph. Is there any way to override this word limit while using Twenty Twenty-Four (or any block template)?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Caio Ferreira

    (@caiohferreiradev)

    Hi sfjwebsfj,

    Hope you’re doing good!

    You can overwrite those settings by editing your theme’s functions.php file, or by using a custom plugin for that.

    In the case of adjusting this limit using code, here’s an example you can use:

    function custom_excerpt_length( $length ) {
    return 200; // Adjust this number to your preferred word limit
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length' );

    In this example, I’ve set the word limit to 200 words, but feel free to change the value according to your needs.

    Remember to customize the code carefully, and always make a backup of your site before making changes to theme files.

    If you’re not comfortable with coding, you can use a plugin like “Code Snippets” to add this code without directly modifying your theme files.

    I’ve found a plugin on the plugin repository that allows you to adjust it without coding called Simply Excerpt. Feel free to test it if you’d like to.

    I hope this helps!

    Sincerely,

    Caio Ferreira

    • This reply was modified 1 year, 3 months ago by Caio Ferreira. Reason: Added plugin links to my comment
    Thread Starter sfjwebsfj

    (@sfjwebsfj)

    Hi Caio, thank you for your reply and solution, but it unfortunately didn’t work for me, both through functions.php and Code Snippets. (Actually, I had already tried the add_filter method and given up.) Since then, I’ve been digging deep into creating a custom excerpt block and found this comment and code in the core post-excerpt block (index.php):

    /*
    * The purpose of the excerpt length setting is to limit the length of both
    * automatically generated and user-created excerpts.
    * Because the excerpt_length filter only applies to auto generated excerpts,
    * wp_trim_words is used instead.
    */
    $excerpt_length = $attributes['excerptLength'];
    $excerpt        = get_the_excerpt( $block->context['postId'] );
    if ( isset( $excerpt_length ) ) {
    $excerpt = wp_trim_words( $excerpt, $excerpt_length );
    }

    So, yeah, they are truncating user-created excerpts with intention. I have been battling this for days and have searched the world over. The only reason given for altering the user-created excerpts, that I have found, is so that if you are using a grid-based layout it will come out more aesthetically pleasing. That is such bad logic it makes me want to cry. That is a challenge for the theme to overcome, not the core.

    Then, to really make sure that YOUR website is the way THEY want it to be, they added this at the end of index.php:

    /**
    * If themes or plugins filter the excerpt_length, we need to
    * override the filter in the editor, otherwise
    * the excerpt length block setting has no effect.
    * Returns 100 because 100 is the max length in the setting.
    */
    if ( is_admin() ||
    defined( 'REST_REQUEST' ) && REST_REQUEST ) {
    add_filter(
    	'excerpt_length',
    	static function () {
    		return 100;
    	},
    	PHP_INT_MAX
    );
    }

    And that is why the intended method of add_filter for making these kinds of changes doesn’t work. Apparently this was added 3 months ago.

    Authors, there does not need to be a max length to achieve your layout goals, which you shouldn’t even have at the core level!

    Again, Caio, thank you for your reply. I wish the people that coded the post-excerpt block would listen.

    Thread Starter sfjwebsfj

    (@sfjwebsfj)

    Solution: I was able to create a custom block that doesn’t abbreviate the excerpt.

    • This reply was modified 1 year, 3 months ago by sfjwebsfj. Reason: marked as resolved
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘FSE Block Editor – Excerpt Block 100 Word Limit’ is closed to new replies.