How to remove a link from the last element?

In the loop displays the breadcrumbs

Is there a way to remove the last element a link ?

add_crumb function( ) {
 $breadcrumbs = new WC_Breadcrumb();

 echo '<a href="'. home_url() .'">Main/</a>';
 foreach ($breadcrumbs->generate() as $breadcrumb) {
 echo '<a href="'. $breadcrumb[0] .'">' . $breadcrumb[0] . '/' . '</a>';
}
}
April 3rd 20 at 18:51
1 answer
April 3rd 20 at 18:53
Solution
for example:
add_crumb function(){
 $breadcrumbs = new WC_Breadcrumb();
$my_Array=$breadcrumbs->generate();
$num=count($my_Array);
$my_i=1;
 echo '<a href="'. home_url() .'">Home</a>/';
 foreach ($my_Array as $breadcrumb) {
if($my_i!==$num){
 echo '<a href="'. $breadcrumb[0] .'">' . $breadcrumb[0] . '</a>/';
}else{
 echo $breadcrumb[0];
}
$my_i++;
}
}
Thanks, but there is a problem when clicking on links gives me error not found

My object is that such an array

Array
(
 [0] => Array
(
 [0] => Clothes and shoes
 [1] => http: //url/product-category/odezhda-i-obuv/
)

 [1] => Array
(
 [0] => Shoes
 [1] => http: //url/product-category/odezhda-i-obuv/obuv/
)

 [2] => Array
(
 [0] => shoes and Sneakers
 [1] => http: //url/product-category/odezhda-i-obuv/obuv/krossovki-i-kedy/
)

)
- Cassandra_Roob commented on April 3rd 20 at 18:56
@Cassandra_Roob, Well, I noticed. You code references refer to the same text)).... - cary.Dietri commented on April 3rd 20 at 18:59
I'm sorry was my mistake, and had instead:
echo '<a href="'. $breadcrumb[0] .'">' . $breadcrumb[0] . '</a>/';

Replace with:
echo '<a href="'. $breadcrumb[1] .'">' . $breadcrumb[0] . '</a>/';
- Cassandra_Roob commented on April 3rd 20 at 19:02
can you want?
echo '<a href="'. $breadcrumb[1] .'">' . $breadcrumb[0] . '</a>/';
- cary.Dietri commented on April 3rd 20 at 19:05
@cary.Dietri, Yes I said above )

This method of withdrawal bread crumbs is the place to be ?

Nope just in the woocommerce filter for adding a class to links ( - Cassandra_Roob commented on April 3rd 20 at 19:08
@Cassandra_Roob, to be honest, never used it... I Think the main thing that he and all the links worked (I'm on Settings "permalinks" in the console).... - cary.Dietri commented on April 3rd 20 at 19:11
@cary.Dietri, but the class object new WC_Breadcrumb() seems to be the dynamics displays

PS Perhaps if the array in the future will change, then it will break - Cassandra_Roob commented on April 3rd 20 at 19:14
@Cassandra_Roob, if You used this class, I noticed warning in the archives(it is necessary to grasp, to rule).
spoiler

5dfd179e48ef6952944145.jpeg

or....
Somewhere at the back of the Kama is at the site your class... it works fine. That's just no link to it. There is a draft corrected, but not fully penetrated him...
spoiler

5dfd18343763f543628561.jpeg
- cary.Dietri commented on April 3rd 20 at 19:17
@cary.Dietri, I understand what you mean about the standard of entries from wordpress ?

If Yes, then you can check is_woocommerce(), otherwise standard - Cassandra_Roob commented on April 3rd 20 at 19:20
@Cassandra_Roob, that's it)) so I haven't watched that in class... thanks... by the way like this link a little if it is useful. - cary.Dietri commented on April 3rd 20 at 19:23
@cary.Dietri, Yes thank you, I looked )

I even tried to use this option:
function breadcrumbs($separator = '" ', $home = 'Home') {

 $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
 $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
 $breadcrumbs = array("<a href=\"$base_url\">$home</a>");

 $last = end( array_keys($path) );

 foreach( $path as $x => $crumb ){
 $title = ucwords(str_replace(array('.php', '_'), Array(", ' '), $crumb));
 if( $x != $last ){
 $breadcrumbs[] = '<a href="'.$base_url.$crumb.'">'.$title.'</a>';
}
 else {
 $breadcrumbs[] = $title;
}
}

 return implode( $separator, $breadcrumbs );
}


But there is one problem, if you go to a category page, then in the breadcrumbs gets product-category, which is not very nice ( - Cassandra_Roob commented on April 3rd 20 at 19:26
@Cassandra_Roob, I agree... the same tried - cary.Dietri commented on April 3rd 20 at 19:29

Find more questions by tags WordPressWooCommerce