Skip to main content

Breadcrumbs

1. Filter to change the Breadcrumb Settings.

The filter will override the breadcrumb options selected by the user under Rank Math SEO → General Settings → Breadcrumbs.

/**
* Filter to change breadcrumb settings.
*
* @param array $settings Breadcrumb Settings.
* @return array $setting.
*/
add_filter( 'rank_math/frontend/breadcrumb/settings', function( $settings ) {
$settings = array(
'home' => true,
'separator' => '',
'remove_title' => '',
'hide_tax_name' => '',
'show_ancestors' => '',
);
return $settings;
});

2. Filter to change Breadcrumb Strings.

The filter will override the breadcrumbs strings selected by the user under Rank Math SEO → General Settings → Breadcrumbs.

/**
* Filter to change breadcrumb strings.
*
* @param array $settings Breadcrumb Strings.
* @return array $strings.
*/
add_filter( 'rank_math/frontend/breadcrumb/strings', function( $strings ) {
$strings = array(
'prefix' => '',
'home' => '',
'error404' => '',
'archive_format' => '',
'search_format' => '',
);
return $strings;
});

3. Filter to change Breadcrumb args.

This filter allows you to change the breadcrumb arguments and the breadcrumb appearance on the front-end as well.

/**
* Filter to change breadcrumb args.
*
* @param array $args Breadcrumb args.
* @return array $args.
*/
add_filter( 'rank_math/frontend/breadcrumb/args', function( $args ) {
$args = array(
'delimiter' => ' / ',
'wrap_before' => '<nav class="rank-math-breadcrumb"><p>',
'wrap_after' => '</p></nav>',
'before' => '',
'after' => '',
);
return $args;
});

4. Filter to change the Breadcrumb HTML.

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);

5. Filter to change the primary term output of the breadcrumbs class.

You can use this filter to change the primary term output of the breadcrumbs class dynamically on the front-end.

/**
* Filter to change the primary term output of the breadcrumbs class.
*
* @param WP_Term $term Primary term.
* @param array $terms Terms attached to the current post.
*/
add_filter( 'rank_math/frontend/breadcrumb/main_term', function( $current_term, $terms ) {
return $current_term;
}, 10, 2 );

6. Filter to change/remove breadcrumb items.

This filter allows developers to make any changes or remove any breadcrumb items dynamically on the front-end. When you change/remove the breadcrumb item with this filter, the changes will also reflect in the Breadcrumb Schema.

/**
* 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 ) {
return $crumbs;
}, 10, 2);

7. Filter to change/remove breadcrumb items from Breadcrumb Snippet.

The changes made using this filter will affect only the Breadcrumb Schema.

/**
* Allow changing Breadcrumb elements in BreadcrumbList snippet
*
* @param array $entity Breadcrumb entity
*/
add_filter( 'rank_math/snippet/breadcrumb', function( $entity ) {
return $entity;
});