get_the_excerpt

最后更新于:2021-11-26 23:52:05

apply_filters( ‘get_the_excerpt’, string $post_excerpt, GC_Post $post )

Filters the retrieved post excerpt.

参数

$post_excerpt

(string)
The post excerpt.

$post

(GC_Post)
Post object.

源文件

文件: gc-includes/post-template.php

View on Trac

function gccodex_format_custom_excerpt( $text ) {
  /**
   * Filters the number of words in an excerpt.
   *
   * @since 2.7.0
   *
   * @param int $number The number of words. Default 55.
   */
  $excerpt_length = apply_filters( 'excerpt_length', 55 );
  /**
   * Filters the string in the "more" link displayed after a trimmed excerpt.
   *
   * @since 2.9.0
   *
   * @param string $more_string The string shown within the more link.
   */
  $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' );
  $text = gc_trim_words( $text, $excerpt_length, $excerpt_more );

  // Format the text
  $text = apply_filters( 'get_the_excerpt', $text );

  return $text;
}

/**
 * Adds a pretty "Continue Reading" link to custom post excerpts.
 *
 * To override this link in a child theme, remove the filter and add your own
 * function tied to the get_the_excerpt filter hook.
 */
function twentyeleven_custom_excerpt_more( $output ) {
  if ( has_excerpt() && ! is_attachment() ) {
    $output .= twentyeleven_continue_reading_link();
  }
  return $output;
}
add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );