WordPress.org

Forums

[resolved] the_excerpt() ignores teaser (6 posts)

  1. rooodini
    Member
    Posted 5 years ago #

    From WordPress Codex "Excerpt":

    When a post has no manual excerpt, WordPress looks for a teaser to use as excerpt. If the post has no teaser either, WordPress generates automatically an excerpt by selecting the first 55 words of the post.

    Is this true? It doesn't seem to be! I think this happens instead:

    When a post has no manual excerpt, WordPress generates automatically an excerpt by selecting the first 55 words of the post.

    That is, teasers are ignored.

    wp_trim_excerpt in wp-includes/formatting.php appears to be the function in question.

    Would be cool if it really worked the way the codex describes. I think a plugin could do this, using:
    add_filter('wp_trim_excerpt', 'my_excerpt_function');

    Any tips?

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    If you don't have anything in the Excerpt box in the Edit Post page, using <?php the_excerpt();?> will cause WP to create an automated excerpt using the first 55 words of your post's content. There is no "teaser" field in native WP.

  3. rooodini
    Member
    Posted 5 years ago #

    Hi esmi,

    Thanks for your response. You are right that there is no "teaser" field. However, on Codex, "teaser" is used to refer to the text before a <!--more--> tag.

    From the same codex page:

    The manual WordPress excerpt is often confused with the automatic excerpt or with the teaser (the part of a post that appears on the front page when you use the More tag). While both are related to the manual excerpt, they are different from it.

    Regards,
    Andy

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    Having re-read that page, I can see where it might cause confusion. I'll pass this onto someone who is more actively involved in Codex documentation than I am. You could also join the wp-docs list and bring this up yourself, if you want.

  5. rooodini
    Member
    Posted 5 years ago #

    I started writing a plugin to match the description in the codex. Didn't get it working though, because when I hook in '<!--more-->' has already been replaced.

    In case it's useful to anyone, here's where I got to:

    function codex_the_excerpt($text, $raw_excerpt) {
    	if ( '' == $raw_excerpt ) {
    		$content = get_the_content('');
    		if(FALSE !== $more_pos = strpos($content, '<!--more-->'))
    		  $text = substr($text, 0, $more_pos);
    	}
      return $text;
    }
    add_filter('wp_trim_excerpt', 'codex_the_excerpt', 0, 2);
  6. rooodini
    Member
    Posted 5 years ago #

    PS Thanks for the suggestion, esmi. I will join the wp-docs list.

    Regards,
    Andy

Topic Closed

This topic has been closed to new replies.

About this Topic