Published on Jul 12, 2018

How to change the length of excerpts

Sridhar Katakam

By default, WordPress displays the first 55 words in excerpts. Let’s see how this number can be changed using the excerpt_length filter.

We need to add the following code:

add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/**
* Change the length of excerpt.
*
* @param int $length The number of words. Default 55.
* @return int New excerpt length.
*/
function custom_excerpt_length( $length ) {
return 20; // number of words. Default is 55.
}

Change 20 to your desired excerpt length.

In Oxygen (or any WordPress site for that matter), there are at least two ways in which code snippets like these can be added.

This will work with the output of Easy Posts element as well as the pre-built Blog components in the Library.

Method 1

Install and activate the Code Snippets plugin.

Add a new Snippet. Give a title of say “Excerpt length” and paste in the code. Select “Only run on site front-end”. Then save the changes and activate.

Method 2

Install and activate my custom functionality plugin.

Add the above code inside wp-content/plugins/my-custom-functionality/plugin.php using a FTP client.

Source: https://codex.wordpress.org/Plugin_API/Filter_Reference/excerpt_length

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-down