WooCommerce – Rank Math Breadcrumb

#945528
  • Resolved Iaina Randrianarivony
    Rank Math free

    Hello,

    My problem regarding the “Breadcrumb” with WooCoomerce.
    The Breadcrumb does not remove the title in the categories.

    For my part, I solved the problem by adding is_product_category() to line 133 of the file ../seo-by-rank-math/includes/frontend/class-breadcrumbs.php

    The result:
    $remove_title = ( is_product_category() || is_single() || is_page() ) && $this->settings['remove_title'];

    Please fix it in the next update. Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello,

    We apologize for the issue you are facing with the Breadcrumbs in WooCommerce. Thank you for raising this concern and for sharing your solution regarding the removal of titles in product categories.

    While we appreciate your input, we cannot make changes to the core files directly. However, we recommend using the provided filters and hooks to customize the behavior of Breadcrumbs without modifying the core plugin files. This ensures that your changes remain intact during updates.

    If you would like to further discuss this or have any additional questions, please feel free to reply to this ticket, and a human agent from the Rank Math Support team will assist you.

    Thank you for your understanding!

    Hello,

    Thank you so much for getting in touch.

    Can you please confirm if you’re referring to the option Hide Post Title in the breadcrumbs settings? If so, that option is meant only for single post/page, not for taxonomies as described in the option:

    Rank Math support

    Hence, only is_single() and is_page() are added in the if statement of that line.

    If you need a permanent solution for your issue, you may refer to this filter code instead:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
        if( is_product_category()) {
    			array_pop($crumbs);
        }
        return $crumbs;
    }, 10, 2);

    You may refer to this guide on how to add filters to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Don’t hesitate to get in touch with us if you have any other questions.

    Hello,

    Yes, I confirm that this concerns the “Hide Post Title” option. I tried the filter code and it works. However, the parent category link is disabled.

    Is there a filter to disable the title and keep the parent category link?

    Thanks.

    Hello,

    Please try this filter instead to make the parent category clickable on your product category breadcrumbs:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
        if( is_product_category()) {
    			unset($crumbs[1]);
            $crumbs[1] = [
    				$category->name,
    				site_url( $category->slug ),
    				'hide_in_schema' => false,
    			];
    		return $crumbs; 
        }
        return $crumbs;
    }, 10, 2); 

    Let us know how this goes.

    Hello,
    I just tried the new filter and it doesn’t work.

    The original Breadcrumb :
    Original Breadcrumb

    After apply the filter :
    After apply filter

    I need this :
    Need This Breadcrumb

    Thank you.

    Hello,

    Please try to replace the filter code with the following one and see if that works for you:

    // Remove the title of the last breadcrumb for product category pages
    add_filter('rank_math/frontend/breadcrumb/items', function ($crumbs, $class) {
        if (is_product_category()) { 
            $last_index = count($crumbs) - 1; 
            if (isset($crumbs[$last_index])) {
                $crumbs[$last_index][0] = ''; 
            }
        }
        return $crumbs;
    }, 10, 2);
    
    // Remove the last separator from the breadcrumbs HTML
    add_filter('rank_math/frontend/breadcrumb/html', function ($html, $crumbs, $class) {
       $html = preg_replace('/<span class="separator"> &raquo; <\/span>(?=\s*<span class="last">)/', '', $html);
        return $html;
    }, 10, 3);
    

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Hello,
    Thank you, it work but I add condition to the filter HTML.

    // Remove the title of the last breadcrumb for product category pages
    add_filter('rank_math/frontend/breadcrumb/items', function ($crumbs, $class) {
        if (is_product_category()) { 
            $last_index = count($crumbs) - 1; 
            if (isset($crumbs[$last_index])) {
                $crumbs[$last_index][0] = ''; 
            }
        }
        return $crumbs;
    }, 10, 2);
    
    // Remove the last separator from the breadcrumbs HTML
    add_filter('rank_math/frontend/breadcrumb/html', function ($html, $crumbs, $class) {
        if (is_product_category()) { 
            $html = preg_replace('/<span class="separator"> &raquo; <\/span>(?=\s*<span class="last">)/', '', $html);
        }
        return $html;
    }, 10, 3);

    Hello,

    We are glad that helped.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)

The ticket ‘WooCommerce – Rank Math Breadcrumb’ is closed to new replies.