WordPress the_excerpt() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints a short summary

Definition

In WordPress, the_excerpt() prints a short summary of the current post. It is perfect for blog lists and search results.

If you wrote an excerpt in the editor, that text is used. If not, WordPress makes one from the first 55 words of the post.

Syntax

A few ways to call the_excerpt().

WordPress
<?php
the_excerpt();
CallWhat it does
the_excerpt()Print the excerpt.
get_the_excerpt()Return the excerpt as a string.
add_filter( 'excerpt_length', ... )Change how many words the automatic excerpt has.
add_filter( 'excerpt_more', ... )Change the text at the end of the excerpt.

It prints the excerpt inside a paragraph. It takes no arguments.

Full declaration
WordPress
the_excerpt(): void

Parameters

ParameterDescription
(none)This function takes no parameters.

Return Value

Return ValueDescription
voidNothing is returned. The excerpt is printed.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Excerpt in a blog list

Show the title and a short summary for each post.

WordPress
<?php while ( have_posts() ) : the_post(); ?>
  <h2><?php the_title(); ?></h2>
  <?php the_excerpt(); ?>
<?php endwhile; ?>

How It Works

  1. The Loop goes through each post.
  2. the_excerpt() prints the short summary in a p tag.
  3. The [&hellip;] is added when the text was cut.

Example 2 — Make the excerpt shorter

Use the excerpt_length filter to change the word count.

WordPress
<?php
function mytheme_excerpt_length() {
  return 20;
}
add_filter( 'excerpt_length', 'mytheme_excerpt_length' );

How It Works

  1. The filter returns the number of words.
  2. Here the automatic excerpt is 20 words long.
  3. This does not change excerpts you wrote by hand.

Example 3 — Change the ending

Use excerpt_more to change the text at the end.

WordPress
<?php
function mytheme_excerpt_more() {
  return '... <a href="' . esc_url( get_permalink() ) . '">Read more</a>';
}
add_filter( 'excerpt_more', 'mytheme_excerpt_more' );

How It Works

  1. The filter returns the text added after a cut excerpt.
  2. get_permalink() gives the link to the post.
  3. The new ending replaces [&hellip;].

Frequently Asked Questions

It prints a short summary of the current post.
From the Excerpt box in the editor, or from the first 55 words of the post if the box is empty.
the_excerpt() prints a summary. the_content() prints the full post.
Use the excerpt_length filter.
Use the excerpt_more filter.

Browse all post functions

Open the functions index for simple guides with examples and FAQs.

Post Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful