Last active
October 12, 2023 21:31
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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