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

Yoast display category description excerpt on category page

I encountered an issue where the plugin does not automatically display anything in categories and tags. If you use the %%category_description%% tag in the settings, it will display all descriptions from the page, which is not ideal. Therefore, let’s create code to truncate it to 170 characters.

One of its useful features is configuring meta descriptions for different sections of your website, such as categories and tags. In this article, we will explore how to use Yoast SEO to configure meta descriptions and excerpts for categories and tags.

1. Go to the plugin settings and configure as shown in the screenshots:

 

2. Creating a function to truncate text: The first step is to create a function that will be used to truncate text to a specified number of characters. This function removes HTML tags, truncates the text, and returns it at the specified character length.

 

3. Configuring meta descriptions for categories: Next, we create a function that will modify the meta description for categories and product categories in Yoast SEO. We use a check to ensure that we are on a category or product category page.

 

4. Configuring meta descriptions for tags: Similarly, we create a function to change the meta description of tags in Yoast SEO. We check if the current page is a tag page.

Now that you have applied this code, the Yoast SEO plugin will use the configured meta descriptions and truncated excerpts for categories and tags on your WordPress website. This will help improve the SEO optimization of your content and make your site more informative for search engines and visitors. Don’t forget to regularly update the meta descriptions to keep them relevant to your content.

Result – automatic display of meta description in categories and tags, as well as its truncation

Leave a Reply

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