get_the_excerpt

Retrieves the post excerpt.

Description

(string) get_the_excerpt( (null) $post = null ); 

Returns (string)

Post excerpt.

Parameters (1)

0. $post — Optional. (null) => null
Post ID or WP_Post object. Default is global $post.

Usage

  1. if ( !function_exists( 'get_the_excerpt' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4. // Optional. Post ID or WP_Post object. Default is global $post. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_the_excerpt($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post-template.php  
  1. function get_the_excerpt( $post = null ) { 
  2. if ( is_bool( $post ) ) { 
  3. _deprecated_argument( __FUNCTION__, '2.3.0' ); 
  4.  
  5. $post = get_post( $post ); 
  6. if ( empty( $post ) ) { 
  7. return ''; 
  8.  
  9. if ( post_password_required( $post ) ) { 
  10. return __( 'There is no excerpt because this is a protected post.' ); 
  11.  
  12. /** 
  13. * Filters the retrieved post excerpt. 
  14. * @since 1.2.0 
  15. * @since 4.5.0 Introduced the `$post` parameter. 
  16. * @param string $post_excerpt The post excerpt. 
  17. * @param WP_Post $post Post object. 
  18. */ 
  19. return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );