Custom Breadcrumbs for Archives
This snippet adds custom breadcrumbs to archive pages, improving navigation and SEO for archive content.
PHP
function custom_archive_breadcrumbs() {
if (is_archive() && !is_admin()) {
echo '<div class="breadcrumbs">';
echo '<a href="' . home_url() . '">Home</a> » ';
if (is_category()) {
echo single_cat_title('Category: ', false);
} elseif (is_tag()) {
echo single_tag_title('Tag: ', false);
} elseif (is_author()) {
echo 'Author: ' . get_the_author();
} elseif (is_day()) {
echo 'Archive for ' . get_the_time('F jS, Y');
} elseif (is_month()) {
echo 'Archive for ' . get_the_time('F, Y');
} elseif (is_year()) {
echo 'Archive for ' . get_the_time('Y');
}
echo '</div>';
}
}
add_action('wp_head', 'custom_archive_breadcrumbs');
Snippet Feedback
Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.
SHARED BY