Home > Dev > WordPress SEO > Breadcrumb Navigation

Breadcrumb Navigation

This code creates a breadcrumb navigation for better user experience and SEO.

// Add this to your theme's functions.php file

function the_breadcrumb() {
    echo '<ul id="breadcrumb">';
    if (!is_home()) {
        echo '<li><a href="' . home_url() . '">Home</a></li><li class="separator"> / </li>';
        if (is_category() || is_single()) {
            the_category(' <li class="separator"> / </li> ');
            if (is_single()) {
                echo '<li class="separator"> / </li>';
                the_title('<li>', '</li>');
            }
        } elseif (is_page()) {
            echo '<li>' . the_title('', '', false) . '</li>';
        }
    } elseif (is_tag()) {
        single_tag_title();
    } elseif (is_day()) {
        echo "<li>Archive for "; the_time('F jS, Y'); echo '</li>';
    } elseif (is_month()) {
        echo "<li>Archive for "; the_time('F, Y'); echo '</li>';
    } elseif (is_year()) {
        echo "<li>Archive for "; the_time('Y'); echo '</li>';
    } elseif (is_author()) {
        echo "<li>Author Archive"; echo '</li>';
    } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {
        echo "<li>Blog Archives"; echo '</li>';
    } elseif (is_search()) {
        echo "<li>Search Results"; echo '</li>';
    }
    echo '</ul>';
}
Back