How to add Category Descriptions in TwentyNineteen

- by

Some themes implement the WordPress Category Descriptions, others do not. Often they’re not necessary, but sometimes they are. Here’s how to add them to the TentyNineteen theme.

Make a copy of the archive.php file and call it category.php. There’s a block of comments at the top, I recommend changing the description to remind you of what this file is in there for. Leave it at the root level of your (child) theme.

Find line 22 (or thereabouts), starting with the_archive_title(). This line is pulling in two lines Category Archives and your category title (Project Diary in this example).

To remove the top line, and simply print a title to the category without it becoming a URL, we can use this little workaround trick to replace the_archive_title() with this:

// print the categry title without a link
foreach((get_the_category()) as $category){
echo '<h1 class="page-title">' . $category->name . '</h1>';
}
// print the category description
the_archive_description('<blockquote class="wp-block-quote">', '</blockquote>');
view raw category.php hosted with ❤ by GitHub

To add the description underneath, we can use the_archive_description() function. It’ll print out the text we set, inclusive of any formatting we choose. TwentyNineteen has several options to choose from. I’m going to use the block quote style, but feel free to use any class you like.

Hope this helps!



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.