Add post type to custom taxonomy breadcrumb

#401098
  • Resolved Sam Underwood
    Rank Math free

    Hey, I’ve created a custom post type (CPT) and a hierarchal custom taxonomy that is assigned to the CPT.

    In the custom taxonomy pages, how do I make it so the main CPT archive page is shown?

    For example, currently, the breadcrumbs show:

    Home > Taxonomy Parent > Taxonomy Child

    I want them to be:

    Home > CPT Home > Taxonomy Parent > Taxonomy Child

Viewing 8 replies - 1 through 8 (of 8 total)
  • Prabhat
    Rank Math agency

    Hello,

    Thank you for contacting the support.

    Please add the below filter to the website and see if it gives you the desired output:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	if(get_post_type() === 'test_cpt'){  // Replace test_cpt with the CPT slug
    		array_splice( $crumbs, 1, 0, array(array(
    			"CPT Home", // Replace with CPT name
    			"https://yourwebsite.com/blog/", // Replace with main CPT URL
    			"hide_in_schema" => false
    		)) );
    	}
    	return $crumbs;
    }, 10, 2);

    Before adding, please replace:
    1. test_cpt with the CPT slug
    2. CPT Home with the CPT name or the text to be displayed in the breadcrumbs
    3. https://yourwebsite.com/cpt-home/ with the main page URL of the CPT

    Here’s a guide you can follow to add the filter:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how that goes.

    Thank you.

    Hello,

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

    Thank you.

    That didn’t work, I’ve added some sensitive data so you can see what I mean on the site

    Hello,

    The filter my colleague provided should help you achieve it, although you need to manually set the breadcrumbs title and other properties before inserting it into the breadcrumbs structure (specifically between home and the taxonomy associated with that CPT).

    Have you tried adding the filter code to your functions.php file?

    If the issue persists, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress login 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.

    Right, so it is working on the taxonomy pages, but on the main post type archive, it’s duplicating the breadcrumb. I’ll add the URL in the sensitive data so you can see.

    I only want this to apply on the taxonomy pages.

    Prabhat
    Rank Math agency

    Hello,

    Please replace the previous code with the below one and see if it gives you the desired output:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	if(get_post_type() === 'test_cpt' && false !== is_tax()){  // Replace test_cpt with the CPT slug
    		array_splice( $crumbs, 1, 0, array(array(
    			"CPT Home", // Replace with CPT name
    			"https://yourwebsite.com/blog/", // Replace with main CPT URL
    			"hide_in_schema" => false
    		)) );
    	}
    	return $crumbs;
    }, 10, 2);

    You’ll need to modify the points I mentioned in my previous reply.

    After adding the code, please clear the website and browser’s cache and see if it helps.

    Let us know how that goes.

    Changed the if statement to just be:

    if( is_tax('card-category') )

    That worked for me, thanks!

    Prabhat
    Rank Math agency

    Hello,

    We’re glad that helped.

    Please feel free to get in touch if you require any further assistance.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Add post type to custom taxonomy breadcrumb’ is closed to new replies.