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> &raquo; ';
        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.

Tags

Language

Did it work?

Save Snippet

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.