Герб Укріїни
Believe in Ukraine and the Armed Forces. Glory to Ukraine!

Yoast display category description excerpt on category page

Article updated in November 2026.

When you use Yoast SEO, category and tag pages do not always get a meta description automatically. If you put the %%category_description%% variable into the search appearance template, Yoast outputs the whole term description. On long descriptions that is far too much for a snippet. This article shows how to cut the description to about 170 characters with a small code snippet.

Yoast SEO lets you set meta descriptions for different parts of the site, including categories and tags. Below, we set up the templates and then use the wpseo_metadesc filter to shorten the text.

1. Configure the templates in Yoast SEO

Open the plugin settings (Yoast SEO → Settings → Categories and tags, in older versions Search Appearance → Taxonomies). Set the meta description template for categories and tags as shown in the screenshots. The template should contain the category or tag description variable.

Yoast also has more general variables for term descriptions. Check the variable list in the template field of your version, because names can differ slightly between releases.

2. Create a function to truncate text

First we need a helper that shortens text to a given number of characters. It removes HTML tags and shortcodes, normalizes whitespace, cuts the text and then removes the last word if it was cut in half. The result never ends in the middle of a word.

Читайте також:  Default page sorting by date in WordPress

Читайте також:  Default page sorting by date in WordPress

The original version of this helper used strip_tags() and a regular expression only. The version above also handles shortcodes, HTML entities and multiple spaces, which are common in term descriptions.

3. Meta descriptions for categories

Next we hook into wpseo_metadesc and replace the description on category pages and on WooCommerce product category pages. The condition makes sure the code runs only on those archives.

4. Meta descriptions for tags

Tags work the same way. We check that the current page is a tag archive and shorten the tag description.

Читайте також:  Default page sorting by date in WordPress

Add all the code to the functions.php file of your child theme, or to a code snippets plugin. Do not edit a parent theme directly, because updates will overwrite your changes.

Result

After you apply the code, Yoast SEO outputs a meta description for categories and tags automatically, and the text is shortened at a word boundary.

<img class="aligncenter wp-image-6863 size-full" src="https://di-grand.com/blog/wp-content/uploads/2023/09/screenshot_4.jpg" alt="" width="948" height=

Leave a Reply

Your email address will not be published. Required fields are marked *