Today i am sharing small snippet that removes Pagination Trail from WooCommerce breadcrumbs.
Some shop owners may dislike this built-in feature and would like remove WooCommerce pagination links from WooCommerce navigation breadcrumb.
First let’s see how is before-after state of this change.
Before:
After:
Now let’s write a snippet for that:
add_filter('woocommerce_get_breadcrumb',function($crumbs,$tthis){
if(strpos($crumbs[count($crumbs)-1][0],'Page ')===0){
unset($crumbs[count($crumbs)-1]);
$args["breadcrumb"][count($crumbs)-1][1]='';
}
return $crumbs;
},10,2);
What this snippet does is simple, it gets generated crumbs from WooCommerce breadcrumb hook, checks if its last element contains pagination trail, and if yes, it removes that part from generated array. And a a result we get the same breadcrumb that the first page has.
Update: if your website is not in English, then don’t forget to change “Page ” string on the line 2 to the corresponding string in your language.
What if it is not working ?
Then it should be checked why it doesn’t work.
Thank you for this!!
You are welcome!
Thank you .. it works .. just a note .. There is a word “Page”, I had to translate it to our language/translation .. it is not working if you have a translation 😉
add_filter(‘woocommerce_get_breadcrumb’,function($crumbs,$tthis){
if(strpos($crumbs[count($crumbs)-1][0],’Stran ‘)===0){
unset($crumbs[count($crumbs)-1]);
$args[“breadcrumb”][count($crumbs)-1][1]=”;
}
return $crumbs;
},10,2);
Hi Gregor. If you can share the URL, i can check it. Or you can contact me.
I guess there might be some different letter or symbol which doesn’t let your code working.
code is implemented for these pages here .. it wasn’t working with Page, but it works with Stran, since word Page is translated to Stran
https://vitacenter.si/kategorija-izdelka/blazine/
Ah now i see – it is working after you translated it. Very good 🙂 (first i thought it didn’t work even after you translated it)
😉 thank you for your tricks!
Hi thank you for your trick but unfortunately it doesn’t work for me .I don’t now why
maybe your website is non-english and you need to change the string “Page” in the code
yes its not English but I don’t know how I change it?? would you please help me??
This is link of my website if you want help me:
https://solokala.com/%D8%AF%D8%B3%D8%AA%D9%87-%D9%85%D8%AD%D8%B5%D9%88%D9%84%D8%A7%D8%AA/%d8%a2%d8%b1%d8%a7%db%8c%d8%b4%db%8c/%d8%a2%d8%b1%d8%a7%db%8c%d8%b4-%da%86%d8%b4%d9%85/
Thank you
Yes, in this case you need to replace Page with برگه
So replace this line
if(strpos($crumbs[count($crumbs)-1][0],’Page ‘)===0){
with
if(strpos($crumbs[count($crumbs)-1][0],’برگه’)===0){
Thank you so much my friend, yes I tried it yesterday but it didn’t work. I changed it but I think there is a problem .
you can contact me and give an access if you want – so i will be able to check it for you
thank you, you made my day 🙂 because I spent a lot of time on this matter
know it is working after your help, I had a mistake. thank you so so much 🙂
great