Title: Filtering archive page headings in WordPress 5.5
Author: Jb Audras
Published: July 30, 2020

---

 [  ](https://profiles.wordpress.org/audrasjb/) [Jb Audras](https://profiles.wordpress.org/audrasjb/)
8:47 am _on_ July 30, 2020     
Tags: [5.5 ( 87 )](https://make.wordpress.org/core/tag/5-5/),
[dev-notes ( 647 )](https://make.wordpress.org/core/tag/dev-notes/)   

# Filtering archive page headings in WordPress 5.5

With WordPress 5.5, theme authors will now be able to easily filterFilter Filters
are one of the two types of Hooks [https://codex.wordpress.org/Plugin_API/Hooks](https://codex.wordpress.org/Plugin_API/Hooks).
They provide a way for functions to modify data of other functions. They are the
counterpart to Actions. Unlike Actions, filters are meant to work in an isolated
manner, and should never have side effects such as affecting global variables and
output. archive pages headings, so they can use their own HTMLHTML HyperText Markup
Language. The semantic scripting language primarily used for outputting content 
in web browsers. markup.

The existing `get_the_archive_title` hook was previously limited to filter the whole
title string used on archive pages. Some contributors pointed out that this filter
was not specific enough to address all theme developers needs related to the archive
pages headings.

In `get_the_archive_title()` this change splits the internal `$title` variable into`
$title` and `$prefix`.

By using the new `get_the_archive_title_prefix` filter, the prefix can now be wrapped
within custom elements or removed completely.

## Basic examples

`get_the_archive_title_prefix` can be used to filter the archive pages heading prefix.
It accepts only one argument, `$prefix`, which is a string containing the text prefix
of the heading.

To replace the archive title prefix with another text, use:

    ```notranslate
    function mytheme_archive_title_prefix( $prefix ){
        $prefix = __( 'Currently viewing archives for:', 'my-theme' ); 
        return $prefix;
    }
    add_filter( 'get_the_archive_title_prefix', 'mytheme_archive_title_prefix' );
    ```

To completely remove the archive title prefix, use:

    ```notranslate
    add_filter( 'get_the_archive_title_prefix', '__return_empty_string' );
    ```

This change also wrap the title part with a `span` element and pass the original
title and prefix to the existing `get_the_archive_title` filter, allowing further
customization to the archive titles.

This filter passes the following arguments:

 * `$title`: Archive title to be displayed
 * `$original_title`: Archive title without prefix
 * `$prefix`: Archive title prefix

Here is a sample example of use:

    ```notranslate
    function mytheme_get_the_archive_title( $title, $original_title, $prefix ) {
        $prefix = '<span class="archive-prefix">' . __( 'Currently viewing archives for:', 'my-theme' ) . '</span>';
        $title  = '<span class="archive-title">' . $original_title . '</span>';
        return $prefix . $title;
    }
    add_filter( 'get_the_archive_title', 'mytheme_get_the_archive_title', 10, 3 );
    ```

---

For full context on this change, see the related tickets: [#31237](https://core.trac.wordpress.org/ticket/31237),
[#38545](https://core.trac.wordpress.org/ticket/38545) and [#42768](https://core.trac.wordpress.org/ticket/42768).

_Note reviewed by [@justinahinon](https://profiles.wordpress.org/justinahinon/)_

[#5-5](https://make.wordpress.org/core/tag/5-5/), [#dev-notes](https://make.wordpress.org/core/tag/dev-notes/)

### Share this:

 * [  Threads ](https://make.wordpress.org/core/2020/07/30/filtering-archive-pages-headings-in-wordpress-5-5/?share=threads)
 * [  Mastodon ](https://make.wordpress.org/core/2020/07/30/filtering-archive-pages-headings-in-wordpress-5-5/?share=mastodon)
 * [  Bluesky ](https://make.wordpress.org/core/2020/07/30/filtering-archive-pages-headings-in-wordpress-5-5/?share=bluesky)
 * [  X ](https://make.wordpress.org/core/2020/07/30/filtering-archive-pages-headings-in-wordpress-5-5/?share=x)
 * [  Facebook ](https://make.wordpress.org/core/2020/07/30/filtering-archive-pages-headings-in-wordpress-5-5/?share=facebook)
 * [  LinkedIn ](https://make.wordpress.org/core/2020/07/30/filtering-archive-pages-headings-in-wordpress-5-5/?share=linkedin)

 1.  ![](https://secure.gravatar.com/avatar/d94bdc8e970ce9c05a299f54838f522dafcf3d9379cfbea2ca2c848497bb6732?
     s=32&d=mm&r=g)
 2.   [leemon](https://profiles.wordpress.org/leemon/)  10:22 am _on_ July 30, 2020
 3.  About time!
 4.  ![](https://secure.gravatar.com/avatar/18f4f7ebdcd48383951a52a88f401bd6460ae74b626016010b1f0604cac90826?
     s=32&d=mm&r=g)
 5.   [Jonathan Desrosiers](https://profiles.wordpress.org/desrosj/)  3:24 pm _on_ 
     July 31, 2020
 6.  +make.wordpress.org/themes/
 7.  ![](https://secure.gravatar.com/avatar/439e60775e30f4c9a5112dc9c998e058f9b99990d4666d5e9e8ddf75bdacbf0b?
     s=32&d=mm&r=g)
 8.   [edmundcwm](https://profiles.wordpress.org/disillusia/)  5:08 am _on_ November
     13, 2020
 9.  After the 5.5 update, the archive page title on my site is showing the span tagtag
     A directory in Subversion. WordPress uses tags to store a single snapshot of a
     version (3.6, 3.6.1, etc.), the common convention of tags in version control systems.(
     Not to be confused with post tags.) because I wrapped `get_the_archive_title()`
     in a `esc_html()`. In this case should I use `wp_kses()` instead or is it even
     necessary to escape `get_the_archive_title()`?
 10.  * ![](https://secure.gravatar.com/avatar/6f505c6be9a951929a99becb6b413dcfa583a5ca3dd0f7320766fee1481f0f82?
        s=32&d=mm&r=g)
      *  [Jb Audras](https://profiles.wordpress.org/audrasjb/)  8:10 am _on_ November
        13, 2020
      * Hi @edmundcwm,
      * I think your best option is to escape the string using `wp_kses()` indeed 🙂
         - ![](https://secure.gravatar.com/avatar/439e60775e30f4c9a5112dc9c998e058f9b99990d4666d5e9e8ddf75bdacbf0b?
           s=32&d=mm&r=g)
         -  [edmundcwm](https://profiles.wordpress.org/disillusia/)  8:12 am _on_ November
           13, 2020
         - Hello [@audrasjb](https://profiles.wordpress.org/audrasjb/)!
         - Noted. Thanks for the input! 😄

Comments are closed.

# Post navigation

[← Block API Updates in 5.5](https://make.wordpress.org/core/2020/07/30/block-api-updates-in-5-5/)

[Controlling Plugin and Theme auto-update email notifications and Site Health infos in WP 5.5 →](https://make.wordpress.org/core/2020/07/30/controlling-plugin-and-theme-auto-update-email-notifications-and-site-health-infos-in-wp-5-5/)