How to change the Rank Math Breadcrumb HTML Output

How to change the Rank Math Breadcrumb HTML Output

This filter allows you to make any changes to the Breadcrumb HTML on the front-end.

/**
 * Filter to change breadcrumb html.
 *
 * @param  html  $html Breadcrumb html.
 * @param  array $crumbs Breadcrumb items
 * @param  class $class Breadcrumb class
 * @return html  $html.
 */
add_filter( 'rank_math/frontend/breadcrumb/html', function( $html, $crumbs, $class ) {
	// theme_breadcrumb_function();
	return $html;
}, 10, 3);

How to make the Rank Math Breadcrumb last item linked

By default, the last item of the Rank Math breadcrumbs will not be linked. If you want to include a link to the last item, then this filter can be customized as follows:

add_filter( 'rank_math/frontend/breadcrumb/html', function( $html, $crumbs, $class ) {
	$html = str_replace('<span class="last">'.get_the_title().'</span>', '<a href="'.get_the_permalink().'">'.get_the_title().'</a>', $html);
	return $html;
}, 10, 3);

For more Rank Math customization snippets check Rank Math’s official blog post here.

About The Author

Leave a Comment

Your email address will not be published.

Scroll to Top