0

Creating Breadcrumbs without a Plugin

1. Removed all separators:

echo '<li class="separator separator-home"> ' . $separator . ' </li>';

2. Remove <strong> tag for last item

<strong class="bread-current...

3. Added separators and ‘decoration’ for the last item to CSS

#breadcrumbs li:after {
 content: ">"; margin-left:10px; margin-right:10px; font-size:16px;
 font-weight:100;
 color:#ccc;
}
#breadcrumbs li:last-child::after { color:rgba(255,255,255,1); }
/* last item */
#breadcrumbs li:last-child { font-weight: bold; color:rgba(0,0,0,.75); }

4. To display all parent categories, replace

} else if ( is_category() ) {
  // Category page
  echo '<li class="item-current item-cat">' . single_cat_title('', false) . '</li>';
}

with

  } else if ( is_category() ) {

    // Get post category info
    $category = get_category( get_query_var( 'cat' ) );

    if(!empty($category)) {
           
      // Get parent any categories and create array
      $get_cat_parents = rtrim(get_category_parents($category->cat_ID, true, ','),',');
                
      $cat_parents = explode(',',$get_cat_parents);
      $cat_parents = array_slice($cat_parents, 0, count($cat_parents) - 1);
                    
      // Loop through parent categories and store in variable $cat_display
      $cat_display = '';
    
      foreach($cat_parents as $parents) {
        $cat_display .= '<li class="item-cat">' . $parents . '</li>';
      }
      echo $cat_display;
    }
    // Category page
    echo '<li class="item-current item-cat">' . single_cat_title('', false) . '</li>';
  }

Breadcrumbs are a navigational technique displaying all visited pages leading from the home page to the currently viewed page. All pages are linked for eas Source: WordPress: Creating Breadcrumbs without a Plugin – Articles – The Web Taylor

alcher

Leave a Reply

Your email address will not be published. Required fields are marked *