excerpt_length

最后更新于:2021-11-26 09:17:46

apply_filters( ‘excerpt_length’, int $number )

Filters the maximum number of words in a post excerpt.

参数

$number

(int)
The maximum number of words. Default 55.

源文件

文件: gc-includes/formatting.php

View on Trac

/**
 * Filter the excerpt length to 80 words on homepage and 50 words on page template
 *
 * @param int $length Excerpt length.
 * @return int modified excerpt length.
 */
function gcdocs_custom_excerpt_length( $length ) {
    if ( is_page_template( 'page-templates/services-page.php' ) ) {
        return 50;
    } else if ( is_front_page() && is_home() ) {
        return 80;
    } else {
        return $length;
    }
}

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