Understanding WordPress Excerpt Generation
What Is Excerpt Generation in WordPress?
WordPress excerpt generation is the process of creating a shortened, summarized version of post content that appears in specific locations on your site. An excerpt is a brief text snippet—typically 55 words by default, though this is customizable—that represents the full post without displaying the entire content. WordPress can generate excerpts in two ways: automatically from your post content, or manually through an excerpt field you fill in yourself.
When you generate an excerpt automatically, WordPress pulls text directly from the beginning of your post's content, removes any HTML tags, and truncates it at a specified word count. This differs fundamentally from manually entering an excerpt, where you have complete control over what text appears and how it's phrased.
Why Excerpt Generation Matters
Excerpt generation serves multiple critical functions across your WordPress site:
- Archive and listing pages: Excerpts allow blog archives, category pages, and search results to display multiple posts without overwhelming visitors with full content. This improves page scanning and helps users quickly identify relevant articles.
- User experience: Instead of displaying entire posts on index pages, excerpts create a cleaner, more organized layout that encourages browsing and navigation rather than forcing readers through complete content immediately.
- Performance: Showing excerpts instead of full content reduces the amount of HTML and text rendered on listing pages, which can improve page load times, particularly on sites with many posts.
- SEO and social sharing: Search engines and social media platforms use excerpts to display preview text. A well-generated excerpt improves how your content appears in search results and when shared on social networks.
- Content consistency: Automatic excerpt generation ensures every post has some descriptive text, preventing blank spaces or missing descriptions on archive pages.
- Readability control: By limiting the length of displayed text, excerpts force you to write compelling introductions that hook readers and encourage them to click through to the full post.
How WordPress Excerpt Generation Works
WordPress handles excerpt generation through a combination of core functions and hooks. Understanding this process helps you control how excerpts appear across your site.
Automatic Excerpt Generation
When you do not manually enter an excerpt, WordPress uses the wp_trim_excerpt() function to automatically generate one. This function follows a specific process:
- It retrieves the post content from the database.
- It removes all HTML tags, shortcodes, and other formatting.
- It strips out any embedded media or special characters.
- It counts words and truncates the text at the default word limit (55 words by default).
- It adds an ellipsis ("...") or custom more text to indicate the excerpt has been cut off.
- It applies any filters or customizations you have configured.
The key point: automatic excerpts are generated on-the-fly from your actual post content. They are not stored separately in the database unless you explicitly save them.
Manual Excerpt Entry
In the WordPress post editor, you will find an "Excerpt" field below the main content area (in the Classic Editor) or accessible through the post settings panel (in the Block Editor). When you manually enter text in this field, WordPress stores it separately and uses this custom excerpt instead of generating one automatically. This gives you complete control over what appears on archive pages.
The Role of the Excerpt Field
The excerpt field in WordPress is a dedicated meta field stored in the post metadata table. When present, it takes priority over automatically generated excerpts. This means:
- If you fill in the excerpt field, WordPress displays that text on archive pages.
- If you leave the excerpt field empty, WordPress generates an excerpt from your post content.
- The excerpt field is completely optional—you can leave it blank for all posts and rely on automatic generation.
Where Excerpts Appear
Excerpts display in several locations by default, depending on your theme and configuration:
- Blog archive pages: The main blog index showing recent posts.
- Category and tag archives: When viewing posts filtered by taxonomy.
- Search results: When displaying search result listings.
- Custom post type archives: Any archive pages for custom post types configured to use excerpts.
- RSS feeds: If your site is configured to show excerpts in feeds instead of full content.
- Homepage: If your homepage is set to display a posts list rather than a static page.
The specific locations where excerpts appear depend entirely on your theme's template files and how they are coded. Some themes display excerpts everywhere possible; others only show them on specific page types.
Technical Implementation: Core Functions
WordPress provides several core functions for working with excerpts:
the_excerpt(): This template tag displays the excerpt for the current post in the loop. It automatically applies filters and formatting. When called, it outputs the excerpt directly to the page.
get_the_excerpt(): This function retrieves the excerpt as a string without displaying it. This allows you to store it in a variable, modify it, or use it in conditional logic before output.
wp_trim_excerpt(): This is the core function that generates automatic excerpts. It accepts the post content as input and returns a trimmed version. You can call this function directly if you need to generate an excerpt from arbitrary text.
excerpt_length filter: WordPress provides a filter hook called excerpt_length that allows you to change the default word count for automatically generated excerpts. By adding a custom function to this filter, you can set different lengths for different post types or contexts.
excerpt_more filter: This filter controls the text appended to the end of truncated excerpts. By default, it is "[...]", but you can customize it to display "Read More", a link, or any other text.
Excerpt Generation vs. Content Display
A critical distinction exists between excerpt generation and full content display. When you use the_excerpt(), WordPress does not display your post content. Instead, it shows only the excerpt. If you want to display full post content on archive pages, you must use the_content() instead, which displays the entire post body.
Many WordPress users confuse these two functions. Using the_content() on archive pages will display every word of every post, making the page extremely long and difficult to navigate. Using the_excerpt() keeps archive pages concise and organized.
How Excerpt Length Works
By default, WordPress counts words, not characters. When the excerpt_length filter is applied, it specifies the maximum number of words to include. WordPress counts from the beginning of the post content and stops at the nearest word boundary after reaching the limit.
For example, if you set the excerpt length to 20 words and your post begins with "This is a sample post about WordPress excerpt generation and how it works on your website," WordPress will display approximately the first 20 words and then truncate, displaying something like "This is a sample post about WordPress excerpt generation and how it works on your..."
The exact truncation point depends on the word count setting and where natural word breaks occur in your content.
Excerpt Stripping and Filtering
WordPress excerpt generation automatically removes several elements from your post content:
- All HTML tags (paragraphs, bold, italic, links, etc.)
- Shortcodes and their output
- Embedded media (images, videos, audio)
- Custom formatting and styling
- Whitespace and line breaks
This stripping process ensures the excerpt is plain text that displays cleanly on archive pages without breaking layouts or introducing unwanted formatting. However, it also means that if your post content includes important formatting or media, the excerpt will not reflect that.
This is one reason many content strategists prefer manually entering excerpts for important posts—it allows you to craft a specific message that may differ from simply truncating the beginning of your content.
The Relationship Between Excerpts and the More Tag
WordPress includes a "More" tag (inserted via the editor) that allows you to specify where post content should be truncated on archive pages. When you insert a More tag in your post, WordPress uses the text before that tag as the excerpt, even if you have not manually filled in the excerpt field.
The More tag takes priority over automatic excerpt generation. If your post contains a More tag, WordPress will use the content before it as the excerpt, regardless of the default word count setting. This gives you precise control over excerpt length on a per-post basis without needing to manually enter text in the excerpt field.
Excerpt Availability Across Post Types
By default, only the standard "post" post type has excerpt support enabled in WordPress. Pages, attachments, and other post types do not display an excerpt field in the editor by default. However, you can enable excerpt support for any post type using the post_type_supports() function or by adding it to the post type registration arguments.
This means excerpt generation is most commonly used for blog posts, but it can be extended to any custom post type you create, such as portfolio items, testimonials, products, or events.
How to Generate Excerpts from Content in WordPress: Complete Strategy and Implementation
WordPress provides multiple methods to generate excerpts from your post content, ranging from automatic generation to manual creation. Each approach has distinct advantages depending on your site structure, theme requirements, and content management workflow. Understanding these methods allows you to choose the most appropriate solution for your specific needs.
Method 1: Use WordPress's Automatic Excerpt Generation
WordPress automatically generates excerpts from your post content without requiring manual input. When you do not provide a custom excerpt, WordPress extracts the first 55 words from your post content and removes all HTML formatting, shortcodes, and tags.
How automatic generation works:
- WordPress reads the post content sequentially from the beginning
- It counts words until reaching the default limit (55 words)
- It strips all HTML tags, formatting, and embedded media
- It appends an ellipsis (...) at the end
- The result displays wherever you call the_excerpt() in your theme
Implementation steps:
- Ensure your theme or template calls the_excerpt() rather than the_content() in archive pages, search results, or home page templates
- Verify that you have not manually entered text in the Excerpt field for posts you want auto-generated excerpts on
- Test the output by visiting your archive pages to confirm excerpts appear correctly
- Check that your theme's functions.php does not override the default excerpt behavior with custom filters
The automatic approach requires no additional setup and works immediately. However, the 55-word default length may not suit every site, and the automatically truncated text sometimes cuts off mid-sentence or removes important context.
Method 2: Customize Excerpt Length Globally
You can modify the default excerpt length from 55 words to any number you prefer by adding a filter to your theme's functions.php file. This change applies site-wide to all automatically generated excerpts.
Add this code to functions.php:
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length' );
Replace 20 with your desired word count. This filter hooks into WordPress's excerpt generation process and changes the cutoff point before the ellipsis is added.
Customizing the excerpt ending:
By default, WordPress appends three dots (...) to truncated excerpts. You can change this using the excerpt_more filter:
function custom_excerpt_more( $more ) {
return ' … Read More';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );
This example replaces the ellipsis with a "Read More" link, though you can use any text or HTML you prefer.
Important considerations:
- Changes to functions.php apply globally to all posts and custom post types using excerpts
- If you switch themes, you may need to reapply these customizations if the new theme uses a different functions.php
- These filters only affect automatically generated excerpts, not manually entered ones
- Very short excerpt lengths (under 10 words) may result in incomplete or unclear text
Method 3: Manually Create Custom Excerpts
The most reliable way to control excerpt content is to write custom excerpts manually. WordPress displays custom excerpts instead of auto-generated ones, giving you complete control over what appears in archives and search results.
Where to find the excerpt field:
- In the block editor (Gutenberg): Look for the Excerpt panel in the document settings on the right sidebar. If not visible, click the three-dot menu and select "Preferences" to enable it.
- In the classic editor: The excerpt field appears below the main content editor as a text box labeled "Excerpt"
- The field accepts plain text or limited HTML formatting depending on your editor version
Best practices for manual excerpts:
- Write excerpts as standalone summaries rather than direct quotes from your content
- Include your primary keyword naturally if it appears in the post
- Keep length between 50 and 160 characters for optimal display in search results and social media
- Make the first sentence compelling to encourage clicks
- Avoid duplicating the same excerpt across multiple posts
- Review excerpts periodically to ensure they still accurately represent updated content
Manual excerpts require more effort but provide superior control and often result in better click-through rates because they are specifically crafted for your audience rather than algorithmically truncated.
Method 4: Generate Excerpts Programmatically in Custom Code
If you need to generate excerpts dynamically within custom templates or plugins, you can use WordPress functions directly in your code.
Using wp_trim_excerpt():
$excerpt = wp_trim_excerpt( $text );
echo $excerpt;
This function accepts a string and returns it trimmed to the excerpt length set by your excerpt_length filter. If you pass an empty string, it uses the post content instead.
Generating excerpts outside the loop:
When working outside the main post loop, you need to specify which post to extract the excerpt from:
$post_id = 42;
$excerpt = wp_trim_excerpt( '', $post_id );
echo $excerpt;
Pass the post ID as the second parameter to generate an excerpt for a specific post.
Custom excerpt generation with get_the_excerpt():
$post_id = 42;
$excerpt = get_the_excerpt( $post_id );
echo $excerpt;
This function returns the custom excerpt if one exists, or generates one from the content if not. It respects all filters and customizations you have applied.
Method 5: Strip Content and Create Excerpts with Custom Filters
For more advanced control, you can create custom filters that modify how excerpts are generated from your content.
Remove specific content types from excerpts:
function remove_shortcodes_from_excerpt( $text ) {
$text = strip_shortcodes( $text );
return $text;
}
add_filter( 'the_excerpt', 'remove_shortcodes_from_excerpt' );
This filter removes all shortcodes before the excerpt is displayed, preventing broken output from gallery, video, or other dynamic content shortcodes.
Remove images and formatting:
function clean_excerpt( $text ) {
$text = strip_tags( $text );
return $text;
}
add_filter( 'the_excerpt', 'clean_excerpt' );
This removes all HTML tags from the excerpt, leaving only plain text. Use this if your theme displays excerpts in a context where formatting could cause layout issues.
Common Mistakes to Avoid
Mistake 1: Confusing the_excerpt() with the_content()
These functions serve different purposes. the_excerpt() displays the excerpt (custom or auto-generated), while the_content() displays the full post body. Using the wrong function means your excerpt customizations will not appear. Check your theme's archive.php and search.php templates to confirm they call the_excerpt().
Mistake 2: Leaving the excerpt field blank expecting automatic generation
Some themes or plugins disable automatic excerpt generation. If you leave the excerpt field empty and nothing displays, check whether your theme requires manual excerpts or if a plugin is filtering the excerpt output. Always test your setup by creating a test post with and without a custom excerpt.
Mistake 3: Using the_content() for archive pages
Displaying full post content on archive pages creates extremely long pages that load slowly and provide poor user experience. Always use the_excerpt() on archives, search results, and category pages. Reserve the_content() for single post views only.
Mistake 4: Setting excerpt length too short
Excerpt lengths under 15 words often fail to convey meaningful information about your post. While shorter excerpts save space, they frequently result in incomplete sentences or lost context. Test different lengths with your actual content to find the balance between space efficiency and clarity.
Mistake 5: Not accounting for HTML in excerpt generation
If your post content contains HTML tags, bold text, links, or other formatting, automatic excerpt generation strips all of this. The resulting text may appear awkward or lose emphasis. Consider whether your content structure requires manual excerpts to preserve important formatting or whether plain text excerpts are acceptable.
Mistake 6: Applying filters globally without testing
When you add custom excerpt filters to functions.php, they affect every post on your site. Always test changes on a staging environment or development site first. Unintended consequences could include excerpts appearing in unexpected locations or breaking layout on pages you did not anticipate.
Mistake 7: Overcomplicating excerpt generation
Some developers create elaborate custom functions to generate excerpts when WordPress's built-in methods would suffice. More complex code introduces more potential for bugs and maintenance issues. Start with automatic generation or manual excerpts, and only add custom logic if you have a specific requirement that built-in methods cannot address.
Mistake 8: Forgetting to update excerpts when content changes
If you use manual excerpts and later update your post content significantly, your excerpt may no longer accurately represent the post. Establish a workflow to review and update excerpts when you make major content revisions.
Choosing the Right Method for Your Site
| Method | Effort Required | Control Level | Best For | Drawbacks |
|---|---|---|---|---|
| Automatic Generation (Default) | None | Low | Small blogs, simple content, rapid publishing | Inconsistent quality, may cut off mid-sentence, limited customization |
| Custom Excerpt Length | Minimal (code change) | Medium | Sites needing consistent excerpt length across all posts | Still depends on content structure, applies to all posts uniformly |
| Manual Excerpts | High (per post) | Maximum | Content-focused sites, SEO-optimized blogs, professional publications | Time-consuming, requires discipline to maintain consistency |
| Programmatic Generation | Medium (development) | High | Custom themes, plugins, advanced implementations | Requires PHP knowledge, maintenance responsibility |
| Custom Filters | Medium (development) | High | Sites needing specific content removal or modification | Complex logic can cause performance issues or unexpected behavior |
Most WordPress sites benefit from a hybrid approach: use automatic generation as a fallback for posts without custom excerpts, but manually create excerpts for important content like homepage featured posts or high-traffic articles. This balances effort with quality.