Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jany-M/c091959d0c430b865ad7 to your computer and use it in GitHub Desktop.
Save Jany-M/c091959d0c430b865ad7 to your computer and use it in GitHub Desktop.
[WordPress] Remove Product Name & URL from WooCommerce Breadcrumbs
<?php
// In your theme, make a new folder woocommerce/global/
// Add this function in a file called breadcrumbs.php, in that folder
// or integrate the existing function accordingly.
/**
* Shop breadcrumb
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.3.0
* @see woocommerce_breadcrumb()
*/
if (!defined('ABSPATH')) {
exit;
}
if ($breadcrumb) {
// Point to end of the array
end($breadcrumb);
// Fetch key of the last element of the array
$lastElementKey = key($breadcrumb);
echo $wrap_before;
foreach ($breadcrumb as $key => $crumb) {
// If this is the last element (Product Name) stop iteration
if($key == $lastElementKey) break;
echo $before;
if (!empty($crumb[1]) && sizeof($breadcrumb) !== $key + 1 ) {
echo '<a href="'.esc_url($crumb[1]).'">'.esc_html($crumb[0]).'</a>';
} else {
echo esc_html($crumb[0]);
}
echo $after;
// If this is the second last element, then don't print delimiter
if ($key !== $lastElementKey -1 ) {
echo $delimiter;
}
}
echo $wrap_after;
}
?>
@Serega1288
Copy link

Thanks :)

@Obroten54
Copy link

File breadcrumb.php (not breadcrumbs.php)
And on 36 line $key + 2 (not + 1)
Nice function, thanks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment