• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / get_comment_excerpt() – Retrieves the excerpt of the given comment.

You appear to be a bot. Output may be restricted

Description

Retrieves the excerpt of the given comment.

Returns a maximum of 20 words with an ellipsis appended if necessary.

Usage

$string = get_comment_excerpt( $comment_ID );

Parameters

$comment_ID
( int|WP_Comment ) optional – WP_Comment or ID of the comment for which to get the excerpt. Default current comment.

Returns

string The possibly truncated comment excerpt.

Source

File name: wordpress/wp-includes/comment-template.php


Lines:

1 to 38 of 38
function get_comment_excerpt( $comment_ID = 0 ) {
  $comment = get_comment( $comment_ID );

  if ( ! post_password_required( $comment->comment_post_ID ) ) {
    $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
  } else {
    $comment_text = __( 'Password protected' );
  }

  /* translators: Maximum number of words used in a comment excerpt. */
  $comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' );

  
/**
 * Filters the maximum number of words used in the comment excerpt.
 *
 * @since 4.4.0
 *
 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
 */
  $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );

  $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' );

  
/**
 * Filters the retrieved comment excerpt.
 *
 * @since 1.5.0
 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
 *
 * @param string     $excerpt    The comment excerpt text.
 * @param int        $comment_ID The comment ID.
 * @param WP_Comment $comment    The comment object.
 */
  return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
}
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 9th December 2020

Primary Sidebar

Information

Function name: get_comment_excerpt
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/comment-template.php
File ref: wp-includes/comment-template.php
Deprecated?: No
API Letters: C,E,G

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites