Snippets: Trim Custom Excerpts

// Trim custom excerpts
add_filter( 'wpex_excerpt_output', function( $output, $args ) {
	if ( $output && ! empty( $args['custom_excerpts'] ) ) {
		$post    = get_post();
		$post_id = $post->ID;
		if ( $post->post_excerpt ) {
			$output = wp_trim_words( $post->post_excerpt, $args['length'], $args['more'] );
		}
	}
	return $output;
}, 10, 2 );

Snippet Type: PHP

Posted Under: Other

All PHP snippets should be added via a child theme's functions.php file.