• Hi,

    Can anyone tell me if the default implementation of get_the_excerpt() function reads a complete post from the database and then trims it? Also where is the logic that determines when a manually defined excerpt (as entered underneath the post in wp-admin) is used instead of the trimmed full post.

    I have a large database containing media rich posts and want to avoid at all costs a trim of full post content in favour of simply downloading the significantly lighter weight manually defined excerpt.

    All input and comments on this are most welcome.

Viewing 1 replies (of 1 total)
  • the function is defined in /wp-includes/post-template.php from line 256

    function get_the_excerpt( $deprecated = '' ) {
    	if ( !empty( $deprecated ) )
    		_deprecated_argument( __FUNCTION__, '2.3' );
    
    	$post = get_post();
    
    	if ( post_password_required() ) {
    		return __( 'There is no excerpt because this is a protected post.' );
    	}
    
    	return apply_filters( 'get_the_excerpt', $post->post_excerpt );
    }

    this function gets the handwritten custom excerpt post_excerpt and passes it to the filter…

    the default filter on the function uses wp_trim_excerpt() which is defined in /wp-includes/formatting.php from line 2175

    function wp_trim_excerpt($text = '') {
    	$raw_excerpt = $text;
    	if ( '' == $text ) {
    		$text = get_the_content('');
    
    		$text = strip_shortcodes( $text );
    
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$excerpt_length = apply_filters('excerpt_length', 55);
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    	}
    	return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
    }

    if this filter function gets some text (which will be from the custom excerpt) then no trimming is done.

Viewing 1 replies (of 1 total)
  • The topic ‘Customising get_the_excerpt()’ is closed to new replies.