[Resolved] Excerpt Field Length

Home Forums Support [Resolved] Excerpt Field Length

Home Forums Support Excerpt Field Length

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1285510
    Andy

    Hi,
    Is there a filter for setting the max number of words displayed from the Excerpt Field? (not the excerpt auto-generated by WordPress/Theme)

    #1285609
    David
    Staff
    Customer Support

    Hi there,

    may i ask why you want to do that when you could just type a shorter excerpt?

    #1285615
    Andy

    Only because they are job vacancy posts and as theres likely to be alot of them I’m not sure the client would want to check how many words they are writing everytime they publish a post.

    #1285907
    David
    Staff
    Customer Support

    I suppose you could re-purpose this function:

    https://docs.generatepress.com/article/activating-read-custom-excerpt/#read-more-text

    Something like this:

    add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
    function tu_excerpt_metabox_more( $excerpt ) {
        $output = $excerpt;	
    
        if ( has_excerpt() ) {
            $output = sprintf( '%1$s <a href="%2$s">%3$s</a>',
                wp_trim_words( $excerpt, 15),
                get_permalink(),
                __( 'Read more', 'generatepress' )
            );
        }
    
        return $output;
    }

    This wp_trim_words( $excerpt, 15) is what sets the number of words to display

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.