Using WordPress ‘post_type_archive_title’ PHP filter

The post_type_archive_title WordPress PHP filter allows you to modify the title of a post type archive page.

Usage

add_filter('post_type_archive_title', 'your_custom_function', 10, 2);

function your_custom_function($post_type_name, $post_type) {
    // your custom code here
    return $post_type_name;
}

Parameters

  • $post_type_name (string) – The name label of the post type.
  • $post_type (string) – The post type itself.

More information

See WordPress Developer Resources: post_type_archive_title

Examples

Change Archive Title for a Custom Post Type

Modify the title of a custom post type archive page, for example, a ‘Books’ post type.

add_filter('post_type_archive_title', 'change_books_archive_title', 10, 2);

function change_books_archive_title($post_type_name, $post_type) {
    if ($post_type == 'books') {
        $post_type_name = 'Our Favorite Books';
    }
    return $post_type_name;
}

Add a Prefix to Post Type Archive Titles

Add a prefix to all post type archive page titles.

add_filter('post_type_archive_title', 'add_prefix_to_archive_title', 10, 2);

function add_prefix_to_archive_title($post_type_name, $post_type) {
    $post_type_name = 'Browse: ' . $post_type_name;
    return $post_type_name;
}

Remove ‘Archives:’ Prefix from Post Type Archive Titles

Remove the ‘Archives:’ prefix from post type archive page titles.

add_filter('post_type_archive_title', 'remove_archives_prefix', 10, 2);

function remove_archives_prefix($post_type_name, $post_type) {
    $post_type_name = str_replace('Archives:', '', $post_type_name);
    return $post_type_name;
}

Append Year to Post Type Archive Titles

Add the current year to post type archive page titles.

add_filter('post_type_archive_title', 'append_year_to_archive_title', 10, 2);

function append_year_to_archive_title($post_type_name, $post_type) {
    $year = date('Y');
    $post_type_name .= ' - ' . $year;
    return $post_type_name;
}

Uppercase Post Type Archive Titles

Make all post type archive page titles uppercase.

add_filter('post_type_archive_title', 'uppercase_archive_title', 10, 2);

function uppercase_archive_title($post_type_name, $post_type) {
    $post_type_name = strtoupper($post_type_name);
    return $post_type_name;
}