Skip to content

Instantly share code, notes, and snippets.

@loorlab
Last active October 12, 2023 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loorlab/c221a6fba7a673447ab32bc3d2462a7e to your computer and use it in GitHub Desktop.
Save loorlab/c221a6fba7a673447ab32bc3d2462a7e to your computer and use it in GitHub Desktop.
Rewrite Title - To change the default output of get_the_archive_title() in WordPress, you can use the get_the_archive_title filter. This allows you to modify the title displayed for archive pages such as category, tag, date, and author archives.
<?php
// functions.php
function custom_archive_title($title) {
if (is_category()) {
$title = 'Category: ' . single_cat_title('', false);
} elseif (is_tag()) {
$title = 'Tag: ' . single_tag_title('', false);
} elseif (is_author()) {
$author = get_queried_object();
$title = 'Author: ' . $author->display_name;
} elseif (is_date()) {
if (is_year()) {
$title = 'Yearly Archives: ' . get_the_date('Y');
} elseif (is_month()) {
$title = 'Monthly Archives: ' . get_the_date('F Y');
} elseif (is_day()) {
$title = 'Daily Archives: ' . get_the_date('F j, Y');
}
}
return $title;
}
add_filter('get_the_archive_title', 'custom_archive_title');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment