CPT breadcrumb small issue with custom taxonomy

#547743
  • Resolved Thorsten R.
    Rank Math free

    I first searched the knowledge base very well, tried a lot, but then realized that what I was looking for was somehow not there. It’s about cpt and breadcrumbs.

    My problem, and I think it’s a small one, is as follows: I have a cpt, let’s call it “cars” for example and an associated taxonomy called “car-categories” with excample content like “Volvo”, “BMW” and so on. I have also set up the primary taxonomy under title & and meta settings and actually most of it works, exactly how I want it:

    1.) my single post breadcrumb looks like expected:

    a) permalink: my-url.com/cpt-slug/custom taxonomy category name NOT SLUG/post title/
    b) example data permalink: my-url.com/cars/volvo/xc40-recharge/
    c) breadcrumb: Home >> Cars >> Volvo >> XC40 Recharge

    2.) my main archive page breadcrumb also looks as expected:

    a) permalink: my-url.com/cpt-slug/
    b) example data permalink: my-url.com/cars/
    c) breadcrumb: Home >> Cars

    3.) problem is my category archive breadcrumb. This one looks like this:

    c) breadcrumb: Home >> Car Categories >> Volvo (Car Categories is without link – it’s the name of my taxonomy)

    It should look like: Home >> Cars >> Volvo

    a) permalink OK: my-url.com/cpt-slug/custom taxonomy category name NOT SLUG/
    b) example data OK permalink: my-url.com/cars/volvo/

    I use a little plugin for my cpt car permalink setup, but this usage has no effect on the breadcrumbs as I tried it out and disabled the plugin. The breadcrumb looks the same without the plugin.

    I hope you understand my issue. I think it’s just a small piece of code snippet at all. Can you help me out?

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

    Thank you for contacting Rank Math and bringing your concern to our attention.

    Please try applying the following filter to see if that works for you.

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	
    	$categories = array_map( function ( $category ) {
    		return $category->slug;
    	}, get_the_category() );
    	
    	if ( in_array( 'cars', $categories ) ) { //replace 'cars' with your category slug
    		$crumbs[1][0] = 'Cars'; // Name
    	   	$crumbs[1][1] = 'https://domain.com/your-url-here'; // Add the desired URL
    	}
    	
    	return $crumbs;
    }, 10, 2);

    Here’s how you can add filters/hooks to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

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

    Thank you.

    Hi,

    thanks for trying to help me, I really appreciate it, but that does nothing at all, sorry. And why “get_the_category” as it’s a taxononmy term that contains category names for the cpt posts in there? I tried “get_the_terms” but that does nothing, too.

    I hope I explained it clearly enough. On the category archive page where I use my cpt in combination with a custom taxonomy term I need following as the breadcrumb:

    Home >> name of my cpt name (not slug) for e.g “Cars” >> name of associated term name

    Would it be easier to provide access?

    I found the solution on my own again, as this guy here had the same problem (maybe he described the problem a little bit better): https://support.rankmath.com/ticket/breadcrumbs-archive-title-dont-shows-on-taxonomy-page/

    The solution he found for himself is the one that worked for me, too.

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	$post_type = get_post_type(get_queried_object());
    	
    	if (is_tax('car-categories')) {
    		$crumbs[1][0] = 'Cars';
    		$crumbs[1][1] = 'http://my-url.com/cars/'; // Change this to match the correct URL
    		
    		$crumbs[2][1] = get_the_title();
    	}
    
    	return $crumbs;
    }, 10, 2);
    

    But I still detected one problemwith that (it will seldom be the case): if my category “volvo” has an additional subcategory “electric” (it could be because my custom taxonomy is hierarchical) and I am on the subcategory page of that taxonomy, the breadcrumb looks fine on first view:

    Home >> Cars >> Volvo >> Electric

    but the link of “volvo” (the main category) is just a title of a single post item listed on that page. That is strange. Any ideas?

    Hello,

    Thank you for your patience.

    In this case, we may need to look at the exact structure of your CPT so we can check and advise accordingly.

    Please share the CPT URL and edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Thank you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Nigel
    Rank Math business

    Hello,

    Thank you for your patience as we check your breadcrumb code.

    Removing the line $crumbs[2][1] = get_the_title(); from the code snippet should fix the snippet URL on your taxonomy page.

    Please do not hesitate to let us know if this doesn’t help or you have any follow-up queries.

    Hi Nigel, thanks very much. I really appreciate that you took a look at my issue. I think I removed that line from the source code before, but probably didn’t reload my browser properly. So much effort on my part for nothing. At this point I would also like to give you a big compliment. I’ve had to use your support several times and it’s by far the best I’ve come across, although I’ve only used the free version so far. This is exemplary and others should take an example from this. Thumbs up!

    Hello,

    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 ‘CPT breadcrumb small issue with custom taxonomy’ is closed to new replies.