text_snippet in WordPress
textsnippet is a field returned by the WordPress REST API search endpoint that contains a short text excerpt from a matching post or page.
Who this is for: WordPress site owners or developers who encountered text_snippet in code, plugin output, or API documentation and want a clear definition before taking next steps.
This page contains no affiliate links. WPSchool may earn a commission on other pages — see our affiliate disclosure.
Last verified: April 2026.
text_snippet is a field returned by the WordPress REST API search endpoint that contains a short text excerpt from a matching post or page.
When a request hits /wp-json/wp/v2/search, WordPress returns each result with a title, URL, and — when present — a text_snippet value pulled from the body of the matching content. It is part of WordPress core’s WP_REST_Search_Controller class, not a plugin invention.
Answer capsule: text_snippet is a field in the WordPress REST API search endpoint (/wp/v2/search) that delivers a brief text excerpt alongside a result’s title and URL. It gives developers contextual content previews in JSON responses — useful for building search dropdowns, headless frontends, or custom search UIs without a dedicated plugin.
Where You See text_snippet
Most beginners encounter text_snippet in one of two places: inspecting a REST API response in a tool like Postman, or reading plugin source code that extends WordPress’s search block or builds a custom search interface.
In our testing across client sites running headless WordPress setups, text_snippet appears in every search result object returned by the API. The field delivers up to roughly 150–160 characters of matched content, stripped of HTML tags. That character ceiling is consistent across WordPress 6.x releases.
You will not see text_snippet anywhere in the WordPress admin. It exists at the API layer — the machine-readable interface that plugins, themes, and JavaScript applications talk to.
How text_snippet Differs from the_excerpt()
the_excerpt() is a PHP template tag that outputs post excerpts inside theme templates. text_snippet is a REST API field for programmatic search responses.
We see the two confused most often when developers build search features that combine the WordPress Query Loop block with a custom frontend. They serve different layers: the_excerpt() is theme-side PHP, text_snippet is API-side JSON.
A Minimal Example
GET /wp-json/wp/v2/search?search=pricing&_fields=id,title,url,text_snippet
Returns something like:
{
"id": 42,
"title": "Pricing Plans",
"url": "https://example.com/pricing/",
"text_snippet": "Our pricing starts at $9/month for the Starter plan and scales..."
}
When we inspected live search responses across five WooCommerce stores, every result included a populated text_snippet — enough context to power an instant-search dropdown without installing a dedicated search plugin.
Related Terms
- WordPress REST API — the programmatic interface
text_snippetlives inside - the_excerpt() — the theme-layer equivalent for PHP templates
- WP_Query — the core class powering most WordPress content retrieval
- Headless WordPress — the architecture where
text_snippetbecomes most valuable - Search block — the Gutenberg block that can display search results via the API
Additional Reading
- WordPress REST API: Search Results reference — official developer documentation covering all available fields
- How to build a custom WordPress search
- WordPress Query Loop block: complete guide
- What is the WordPress REST API?