A guide on how to use, edit and customise WordPress archive titles

Written by Mark Wilkinson on February 16, 2021

This article is a comprehensive guide on how to use, modify and customise WordPress’ the_archive_title() function, used on many different archive views.

What is an archive page view in WordPress?

WordPress has many archive page views. These are views which are dynamically generated rather than having an actual page in the WordPress admin that can be edited. WordPress also has a function which can be used to dynamically generate a title or heading on those pages depending on the page’s context.

Examples of WordPress archive pages

There are many examples of WordPress archive pages, for example:

What is the archive title function, what does it do and how do you use it?

WordPress uses a function named the_archive_title(), usually at the top of the archive templates in your theme in order to dynamically generate a suitable title for the page. Since the function is used on many different types of pages, it generates a suitable title for each archive view.

The function itself is relatively simple and is a wrapper function for echoing get_the_archive_title(). You can view the code for the archive title function on Github.

It completes a series of if/else statements and then sets a title based on which type of archive view is being shown.

For example if the user is viewing a category archive page, the title will look like this:

Category: {Category Name}

The {Category Name} part in the example of above would be replaced with the name of the category archive being viewed. For example, if we are viewing the category archive page for the “General” category, the title would look like this:

Category: General

If the user is viewing an author archive page, the function generates a title like this:

Author: {Author Display Name}

The {Author Display Name} part in the example above gets replaced depending on which author archive page is being viewed. For example if this was my author archive page, it would display like this?

Author: Mark Wilkinson

You can use this function in your theme anywhere on an archive page. The wrapper function takes 2 parameters, $before and $after. This is to allow you to output some content before and after the title is output. This is perfect for opening and closing HTML tags, most likely a h1.

How do you edit or customise the output of the archive title in WordPress?

Often users want to remove the archive title prefix which displays on category archives and also on post type archive by default. The prefix is “Category:” on a category archive page and “Archives” on a post type archive page. More often that not, clients want to remove this archive title prefix.

Thanks to the extensibility of WordPress, making changes to the way in which the archive titles are output in WordPress is pretty straightforward with a simple piece of code. You can either add this code to your themes functions.php, or better still add it as part of a modifications plugin that you can activate on your site. This means if you change themes you won’t lose this feature.

Looking back at the get_the_archive_title() function again we can see that towards the end of that code, the generated title is passed through a WordPress filter like so:

return apply_filters( 'get_the_archive_title', $title, $original_title, $prefix );

This is great because it allows developers to change the output. Since it is passed through a filter, this means WordPress is passing the data (the title) to us to modify and then we can pass it back.

To do this we can create a simple function to make the necessary changes and hook this function into WordPress using the filter provided.

In this example we are changing the category archive titles to display in the following format:

View all posts in {Category Name}

In this example the {Category Name} part is again replaced with the name of the category archive being viewed.

If you are looking to target other archive page views you can use any of the conditional functions in WordPress in a similar way to is_category() in the example above.

Learn more about customising archive titles with filters

If you want to learn more about how to customise the WordPress archive titles using the WordPress filters available, then take a look at this video.

The Highrise Digital archive title control plugin for WordPress

At Highrise Digital, we found that we were making some of the same edits on many of the website projects that we build.

Therefore to try and speed things up we decided to package these edits into a plugin that we could use on our client websites to give clients better control over the archive titles on their WordPress sites.

The Highrise Digital Archive Title Control plugin allows site authors and editors to control the archive titles for: