bongzilla

Untitled

Apr 2nd, 2021
637
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter('wpseo_breadcrumb_single_link' ,'change_yoast_single_link', 10 ,2);
  2.  
  3. $COUNT_OF_ITEM = 0;
  4.  
  5. function change_yoast_single_link($link_output, $link ){
  6.     global $wp;
  7.     global $COUNT_OF_ITEM;
  8.     // складываем сюда результат сформированного ОДНОГО линка
  9.     $result = array();
  10.     // определяем текущую страницу
  11.     $curr_page = home_url(add_query_arg(array(), $wp->request));
  12.  
  13.     // проверяем, если текущая страница, то делаем крошку БЕЗ ссылки
  14.     if($link["url"] === $curr_page . "/") {
  15.         $COUNT_OF_ITEM = $COUNT_OF_ITEM + 1;
  16.         $text = $link["text"];
  17.  
  18.         array_push($result, "<li itemprop=\"itemListElement\" itemscope itemtype=\"https://schema.org/ListItem\"><span itemprop=\"name\">{$text}</span><meta itemprop=\"position\" content=\"{$COUNT_OF_ITEM}\"></li>");
  19.     } else {
  20.         $COUNT_OF_ITEM = $COUNT_OF_ITEM + 1;
  21.         $text = $link["text"];
  22.         $url = $link["url"];
  23.  
  24.         array_push($result, "<li itemprop=\"itemListElement\" itemscope itemtype=\"https://schema.org/ListItem\"><a rel=\"nofollow\" itemprop=\"item\" title=\"{$text}\" href=\"{$url}\"><span itemprop=\"name\">{$text}</span><meta itemprop=\"position\" content=\"{$COUNT_OF_ITEM}\"></a></li>");
  25.     }
  26.  
  27.     $html_output = "";
  28.  
  29.     foreach ($result as $idx=>$crumb) {
  30.         $html_output .= $crumb;
  31.     }
  32.  
  33.     return $html_output;
  34. }
  35.  
  36. add_filter('wpseo_breadcrumb_output', 'change_breadcrumb_names1');
  37.  
  38. function change_breadcrumb_names1($output) {
  39.     $output = str_replace("<span>", "", $output);
  40.     $output = str_replace("</span>", "", $output);
  41.     return $output;
  42. }
RAW Paste Data