Adding breadcrumbs to all pages

Hi, I want to add breadcrumbs (I’m using Yoast) to all pages, how can I do that?

Hi,
This would require inserting a custom block into the hivepress/v1/templates/page template with a custom code snippet. Please note that there may be issues with how breadcrumbs detect the page hierarchy Breadcrumbs

Rankmath give me this code to use in the theme.

<?php if (function_exists('rank_math_the_breadcrumbs')) rank_math_the_breadcrumbs(); ?>

Can you advice which path / where should I insert this code so the breadcrumbs will be shown in the whole website?

Thank you.

Please try this PHP snippet but please note that it can require further customization

add_filter(
	'hivepress/v1/templates/page', 
	function($template) {
		if (!function_exists('rank_math_the_breadcrumbs')){
			return $template;
		}
		
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'page_header' => [
						'blocks' => [
							'custom_breabcrumbs' => [
								'type' => 'content',
								'content' => do_shortcode('[rank_math_breadcrumb]'),
								'_order' => 1000,
							],
						],
					],
				],
			]
		); 
	},
	1000
);

Thank you. This does not work for me. I insert it in the fumction.php

Please use the Code Snippets plugin to add and manage custom PHP code snippets Code Snippets – WordPress plugin | WordPress.org

Hi, yevhen.

Thank you for the code, I had almost the same issue. But now I need to exclude vendor from breadcrumbs. Is it possible?

Can you tell me please how did you insert the code into the theme so it will show site wide?

In function.php

1 Like

You can place custom PHP snippets in the child theme’s functions.php file (not in the parent theme one, any changes are reset on update) or via the Code Snippets plugin.

I’ve tried Code Snippets plugin. Doesn’t work at all.

  1. Please check this tutorial and please make sure that you have correctly enabled breadcrumbs in the Rank Math settings How to Enable Breadcrumbs on Your Website with Rank Math SEO » Rank Math

  2. Please try this PHP snippet to not show breadcrumbs on the single vendor page

add_filter(
	'hivepress/v1/templates/page', 
	function($template) {
		if (!function_exists('rank_math_the_breadcrumbs') || 'vendor_view_page' === hivepress()->router->get_current_route_name()){
			return $template;
		}
		
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'page_header' => [
						'blocks' => [
							'custom_breabcrumbs' => [
								'type' => 'content',
								'content' => do_shortcode('[rank_math_breadcrumb]'),
								'_order' => 1000,
							],
						],
					],
				],
			]
		); 
	},
	1000
);

I successfully made it with yoast breadcrumbs. but I find some issue, when I’m in a listing page the first page in the navigation takes me to 404 page.

Example: home>listings>host>studio in new york

So when I click on “listing” it’s taking me to 404 page.

And another issue is that the structure shows the host page, and any change I try to do from Yoast setting to the breadcrumbs structure does not appear on listing page only in the category page. what can I do to change the “Host” page to the region structure in the listing page?

  1. Please refresh the permalink structure in Settings/Permalinks (choose any structure with %postname% if the default one is selected) and check if this issue persists.

  2. Sorry, there’s no simple code snippet for this, it would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work https://fvrr.co/32e7LvY

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.