bongzilla

Untitled

Mar 14th, 2021
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Maxim Botsman, [14.03.21 16:47]
  2. <?php
  3. //Хлебные крошки
  4.  
  5. add_filter( 'wpseo_breadcrumb_links', 'wpseo_breadcrumb_add_woo_shop_link' );
  6.  
  7. function wpseo_breadcrumb_add_woo_shop_link( $links ) {
  8. global $post;
  9. global $wp;
  10. $current_url = home_url(add_query_arg(array(), $wp->request));
  11.  
  12. if ( is_woocommerce() ) {
  13. $breadcrumb[] = array(
  14. 'url' => get_permalink( woocommerce_get_page_id( 'shop' ) ),
  15. 'text' => 'Услуги',
  16. );
  17.  
  18. if ( strpos($current_url, "shop") !== false ) {
  19. array_pop( $links );
  20. }
  21.  
  22. array_splice( $links, 1, -2, $breadcrumb );
  23. }
  24.  
  25. return $links;
  26. }
  27.  
  28. add_filter( 'wpseo_breadcrumb_links', 'yoast_seo_breadcrumb_append_link' );
  29. function yoast_seo_breadcrumb_append_link( $links ) {
  30. global $post;
  31. global $wp;
  32.  
  33. if ( is_single ( 123456 ) ) {
  34. $breadcrumb[] = array(
  35. 'url' => site_url( '/blog/' ),
  36. 'text' => 'Блог',
  37. );
  38. array_splice( $links, 1, -2, $breadcrumb );
  39. }
  40.  
  41. return $links;
  42. }
  43.  
  44. add_filter('wpseo_breadcrumb_single_link' ,'add_single_link', 10 ,2);
  45.  
  46. function add_single_link($link_output, $link ){
  47. global $wp;
  48. $output = array();
  49. $current_url = home_url(add_query_arg(array(), $wp->request));
  50. // a bits for debug
  51. // echo $link["url"] . " --- " . $current_url;
  52. // echo "<br />";
  53.  
  54. if($link["url"] === $current_url . "/") {
  55. array_push($output, "<span class=\"current-page-breadcrumb\">".$link["text"]."</span>");
  56. } else {
  57. array_push($output, "<span><a href=". $link["url"] .">" . $link["text"] . "</a></span>");
  58. }
  59.  
  60. $html_output = "";
  61.  
  62. foreach ($output as $idx=>$crumb) {
  63. $html_output .= $crumb;
  64. }
  65.  
  66. return $html_output;
  67. }
  68. ?>
RAW Paste Data