Function Reference/get the excerpt

跳转至: 导航搜索


Returns the excerpt of the current post with the "[...]" text at the end, which is not a "read more" link. This template tag must be used within The Loop. Alternatively, the_excerpt() can be used to directly display the excerpt, but it also adds opening and closing <p> tags to the string returned by get_the_excerpt().


<?php $excerpt = get_the_excerpt( $deprecated ) ?>


$deprecated is not required.

Return Values

  • If the post does not have an excerpt, this function applies wp_trim_excerpt to the post content and returns that generated string with "[...]" at the end. wp_trim_excerpt is applied via the get_the_excerpt filter and can be removed.
  • For password protected pages it returns a string, which has a default value of "There is no excerpt because this is a protected post." This text can be changed in the function definition.
  • If the post has an excerpt and is not password protected, it returns the excerpt as a string.


get_the_excerpt() can be used to retrieve and store the value in a variable, without outputting it to the page.

$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
	// Some string manipulation performed
echo $my_excerpt; // Outputs the processed value to the page

Use get_the_excerpt() to print an excerpt by specifying a maximium number of characters.


function the_excerpt_max_charlength($charlength) {
	$excerpt = get_the_excerpt();

	if ( mb_strlen( $excerpt ) > $charlength ) {
		$subex = mb_substr( $excerpt, 0, $charlength - 5 );
		$exwords = explode( ' ', $subex );
		$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
		if ( $excut < 0 ) {
			echo mb_substr( $subex, 0, $excut );
		} else {
			echo $subex;
		echo '[...]';
	} else {
		echo $excerpt;

Change Log

Since: 0.71

Source File

get_the_excerpt() is located in onlyincludecodewp-includes/post-template.php/code/onlyinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Template Description

Link to the source code on


  1. filename
  2. (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.


Link to the stable version: pre检查到模板循环:模板:Trac/pre

Link to trunk: pre检查到模板循环:模板:Trac/pre




includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude


This Template is used by Codex:Template Messages.


pre 检查到模板循环:模板:Message /pre