G
G
Genri_Rus2019-12-20 19:17:31
WordPress
Genri_Rus, 2019-12-20 19:17:31

How to remove the link from the last element?

Breadcrumbs are displayed in the loop
Is it possible to somehow remove the link from the last element?

function add_crumb( ) {
  $breadcrumbs = new WC_Breadcrumb();
  
  echo '<a href="'. home_url() .'">Главная/</a>';
  foreach ($breadcrumbs->generate() as $breadcrumb) {
  echo '<a href="'. $breadcrumb[0] .'">' . $breadcrumb[0] . '/' . '</a>';
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Brumer, 2019-12-20
@Genri_Rus

for example like this:

function add_crumb(){
  $breadcrumbs = new WC_Breadcrumb();
  $my_Array=$breadcrumbs->generate();
  $num=count($my_Array);
  $my_i=1;
  echo '<a href="'. home_url() .'">Главная</a>/';
  foreach ($my_Array as $breadcrumb) {
    if($my_i!==$num){
      echo '<a href="'. $breadcrumb[0] .'">' . $breadcrumb[0] . '</a>/';
    }else{
      echo $breadcrumb[0];
    }
  $my_i++;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question