how to make a custom breadcrumb hierachy

#380632
  • Resolved Graeme Harris
    Rank Math free

    Hi there,

    I’ve been reading all over breadcrumbs and am learning a lot but am stuck on this.

    I’ve tried using HTML to add a custom nav class of breadcrumbs for a page and then tested the URL in search console, so I understand that you need a special schema mark up for breadcrumbs for google to detect it as such.

    Rankmath seems to be the way to do this.

    I have a custom post type and various taxonomies which it applies to.

    The top level taxonomy (normally doesn’t have a page) I have created a custom single page for, and I want this to be linked in the breadcrumb trail.

    I also have another page, outside of any taxonomies, which I would like to set as the first item in the list of the breadcrumb trail.

    I don’t see anyway to create a custom breadcrumb hierarchy to achieve this? Even with rankmath pro?

    How can I add whichever list items I want to my pages bread crumb trail?

    Thank you!!
    G

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

    Hello,

    Thank you for contacting the support.

    You will need to modify and use this filter to achieve the desired output:
    https://rankmath.com/kb/filters-hooks-api-developer/#change-breadcrumb-html

    And to modify the breadcrumbs Schema, this filter can be used:
    https://rankmath.com/kb/filters-hooks-api-developer/#change-remove-items-from-breadcrumb-snippet

    Hope this helps.

    Thank you.

    Hey Prabhat,

    this is super helpful thank you, it seems like there is the functionality to customize whatever you like here.

    Can you direct me to any examples of code for,

    4. Filter to change the Breadcrumb HTML.
    and
    7. Filter to change/remove breadcrumb items from Breadcrumb Snippet.

    So I can see how the code looks like in application to real pages?

    Primarily I want to set a custom breadcrumb hierarchy for specific taxonomies & their archive pages only.

    It would also be awesome to be able to do this for individual pages as well, but because all the pages of my website have been created individually and not with a taxonomy (except the business directory listings & their taxonomies), I think I would have to individually specify a list of page URL’s to apply a certain breadcrumb list to, if that makes sense.

    Thanks again, this is exciting to see that it’s possible!
    G

    Nigel
    Rank Math business

    Hello,

    Filter to change the Breadcrumb HTML.
    and

    The following snippet wraps the breadcrumbs with an H6 tag:

    
    add_filter( 'rank_math/frontend/breadcrumb/html', function( $html, $crumbs, $class ) {
    	$html = '<h6>'.$html.'</h6>';
    	return $html;
    }, 10, 3);
    

    The following example modifies the breadcrumb for a custom taxonomy archive:

    
    /**
                 * Allow changing or removing the Breadcrumb items
                 *
                 * @param array       $crumbs The crumbs array.
                 * @param Breadcrumbs $this   Current breadcrumb object.
                 */
                add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
                    if(is_singular('health_term')){
                        $modifiedCrumb  = array(
                            "0" => esc_html('Men\'s Health A-Z'),
                            "1" => esc_url('/mens-health-a-z/'),
                            "hide_in_schema" => false
                        );
                        $crumbs[count($crumbs)-2] = $modifiedCrumb;
                    }
                    //var_dump($crumbs); //view breadcrumb structure.
                    // And return the breadcrumbs
                    return $crumbs;
                }, 10, 2);
    

    In the above filter you can uncomment the line with var_dump($crumbs); to view the breadcrumb structure.

    Hope that helps. Please let us know if you have questions.

    Thanks Nigel.

    From your point of understanding I have a question for you, I’ve been trying to learn as much as I can about how this all works.

    If I were to insert the JSON-LD script for breadcrumbs into my page header, and then just manually put in some HTML, something like “nav class =”breadcrumb” aria-label=”breadcrumbs” ahreflink page … etc… nav”, does this HTML somehow need to call or reference the JSON-LD script?

    I know that the page will function fine, but from your knowledge, as long as my manually created JSON-LD script structures the breadcrumbs the same way I describe them in my nav section, there isn’t any need to somehow call or reference the JSON-LD script from the HTML for the breadcrumbs which appear on page?

    Sorry if this is a bit out of your scope, as I’m learning all this, I’m not sure where I can go otherwise to ask questions of knowledgeable people.

    Thanks again!
    G

    Hello,

    You don’t need to reference your Breadcrumbs Schema from within the HTML markup.

    The only thing you need to make sure of is that the same structure you have in your HTML code is also in the Breadcrumb Schema markup, as you already mentioned in your reply.

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

    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 5 replies - 1 through 5 (of 5 total)

The ticket ‘how to make a custom breadcrumb hierachy’ is closed to new replies.