Adjust WordPress archive headings in the theme

In this tutorial, I will show you how you can customize the WordPress archive headings in the theme according to your wishes. By default, archive titles are displayed on all pages for categories, keywords, authors, and monthly archives.

Since version 4.1 WordPress provides the function the_archive_title to display the archive headings. For theme developers, there is no need to manually output each title for the various archive pages such as categories and keywords. The_archive_title now takes on this task.

Most current and modern sites should therefore use this feature. Therefore, in many themes, only a common archive.php file is required instead of a category.php, tag.php, author.php and archive.php for the various archives, as was previously the case. An example of this approach is TwentySixteen.

A look behind the scenes of the function

the_archive_title is just a wrapper function for outputting the archive heading. The actual title of the archive is generated in the get_the_archive_title function. The different types of archive pages are queried in a long if-else branch and the title is created accordingly.

A look at the source code of the function shows us that at the end the title is returned by a get_the_archive_title filter, which can be used to subsequently adapt the archive headings in a theme or plugin.

Remove "Category:", "Keyword:" and "Author:" from the WordPress archive headings

If you only want to display the name of the category, keyword or author on the archive pages without additional text, you can change the standard functionality of the archive title with a small snippet of code. The function uses the filter mentioned above.

Change WordPress archive headings and use different texts

In addition to removing the standard texts for the archive titles, these can also be changed and renamed. This works with a slightly modified code snippet, which again uses the get_archive_title filter:

Please note: The two code snippets only work if your theme also uses the function the_archive_title to output the archive headings. I also recommend using the code snippets in the functions.php of a child theme.

* Update: Change archive title without code scraps

In the meantime I have also published a plugin with which the archive headings can be adjusted directly in the WordPress backend - without any code snippets.

More information on this in my post on the Custom Archive Titles Plugin.