excerpt_length WordPress Filter Hook

The excerpt_length hook allows you to control how long the excerpt is on your WordPress site. This can be useful if you want to control how much content is displayed on your home page or other archive pages.

apply_filters( 'excerpt_length', int $number ) #

Filters the maximum number of words in a post excerpt.


Parameters

$number

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


Top ↑

More Information

Use this filter if you want to change the default excerpt length.

To change excerpt length, add the following code to functions.php file in your theme adjusting the “20” to match the number of words you wish to display in the excerpt:

function mytheme_custom_excerpt_length( $length ) {
    return 20;
}
add_filter( 'excerpt_length', 'mytheme_custom_excerpt_length', 999 );

Make sure to set the priority correctly, such as 999, otherwise the default WordPress filter on this function will run last and override what you set here.


Top ↑

Source

File: wp-includes/formatting.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More