Modify breadcrumbs

#623966
  • Resolved Michael Brown
    Rank Math free

    How do you modify the breadcrumb path so I can add pages that are not automatically created.
    For example if my url is: home.com/webpage the breadcrumbs created will be “home > webpage” for that page but if wanted the breadcrumbs to be something like “home > hubpage > subhubpage > webpage” how would I achieve this?

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you so much for getting in touch.

    Usually, the most straightforward way to do this is to assign a parent page to the “/webpage” page, however, if those pages are indeed dynamic and not created via WP dashboard, you may need to make use of our breadcrumbs filter to modify the current breadcrumbs path. You may refer to this example code:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	$item1 = ['hubpage', 'https://yourdomain.com/hubpage/' ];
    	array_splice( $crumbs, 1, 0, array($item1) );
    
    	$item2 = ['subhubpage', 'https://yourdomain.com/subhubpage/' ];
    	array_splice( $crumbs, 2, 0, array($item2) );
    	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/

    Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.

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

The ticket ‘Modify breadcrumbs’ is closed to new replies.