WordPress Breadcrumb Function

Description

  1. Copy Below PHP Code and paste it in your theme functions.php file
  2. Copy an Paste the below html code where you want to show breadcrumb for example (header.php)
  3. Copy and paste the below CSS into your stylesheet file and make adjustments as needed for styling

HTML Source Code

                        
                          <div class="breadcrumb"><?php get_breadcrumb(); ?></div>                        
                        

CSS Source Code

                        
                          .breadcrumb {
    padding: 8px 15px;
    margin-bottom: 20px;
    list-style: none;
    background-color: #f5f5f5;
    border-radius: 4px;
}
.breadcrumb a {
    color: #428bca;
    text-decoration: none;
}                        
                        

PHP Source Code

                        
                          function get_breadcrumb() {
    echo '<a href="'.home_url().'" rel="nofollow">Home</a>';
    if (is_category() || is_single()) {
        echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
        the_category(' &bull; ');
            if (is_single()) {
                echo " &nbsp;&nbsp;&#187;&nbsp;&nbsp; ";
                the_title();
            }
    } elseif (is_page()) {
        echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
        echo the_title();
    } elseif (is_search()) {
        echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;Search Results for... ";
        echo '"<em>';
        echo the_search_query();
        echo '</em>"';
    }
}                        
                        


Post Categories