-
Hello, as you can see in the picture, I need to change the following values:
1-itemListElement -> item -> id
2-itemListElement -> item -> name
On the category page
How should I do this?
marked with an arrow
-
Hello,
Thank you for reaching out to us regarding customizing the Breadcrumb Schema on your category page. To change the values itemListElement -> item -> id and itemListElement -> item -> name on the category page, you can achieve this by using Rank Math’s filters.
Here is a code snippet that you can use to customize the Breadcrumb Schema on your category page:
/** * Filter to customize Rank Math Breadcrumb Schema on category pages. */ add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) { // Check if we are viewing a category page if ( is_category() ) { // Customize the itemListElement -> item -> id $crumbs[0]['item']['id'] = 'your_custom_id_value'; // Customize the itemListElement -> item -> name $crumbs[0]['item']['name'] = 'Your Custom Name'; } return $crumbs; }, 10, 2 );
You can add this code snippet to your theme’s functions.php file or use a custom plugin like Code Snippets to add this filter. Make sure to replace ‘your_custom_id_value’ and ‘Your Custom Name’ with the desired values you want to display.
If you encounter any issues or need further assistance, feel free to reach out to our dedicated support team here.
We hope this helps in customizing the Breadcrumb Schema on your category page. If you have any more questions, please let us know!
Sources:
How to Fix “Either ‘name’ or ‘item.name’ should be specified” Error » Rank Math
How to Add the itemListElement Property Using Rank Math » Rank Math
How to Customize Breadcrumbs in Rank Math » Rank Math
Rank Math’s Content Analysis Tests For Archive Pages » Rank Math
How to Enable Breadcrumbs on Your Website With Rank Math SEO » Rank Mathdont work
And that this is on the WooCommerce product category pageHello,
Could you please share the code you have added so we can check?
Meanwhile, update the condition
if ( is_category() )
to this one to apply it to your product categories onlyif ( is_product_category())
Looking forward to helping you.
add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) { $url = home_url($_SERVER['REQUEST_URI']); if (strpos($url, 'web/theme/wp/')) { $crumbs[0]['item']['id'] = 'https://site.com/c/web/theme/wp/'; $crumbs[0]['item']['name'] = 'wp theme'; } return $crumbs; }, 10, 2 );
Hello,
Please replace your existing code snippet with the following modified version:
add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) { // Check if we are viewing a WooCommerce product category page if ( is_product_category() ) { // Customize the itemListElement -> item -> id $crumbs[0]['item']['id'] = 'https://site.com/c/web/theme/wp/'; // Customize the itemListElement -> item -> name $crumbs[0]['item']['name'] = 'wp theme'; } return $crumbs; }, 10, 2 );
This modified code snippet specifically targets WooCommerce product category pages. It should correctly customize the values of itemListElement -> item -> id and itemListElement -> item -> name for your product category breadcrumbs.
Please replace ‘https://site.com/c/web/theme/wp/’ with the desired ID value, and ‘wp theme’ with the custom name you want to display.
If you continue to experience issues or have any further questions, please let us know, and we’ll be happy to assist you further.
thank you, but I said that it does not work.
I was able to change the “name” with the code below:add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs ) { $url = home_url($_SERVER['REQUEST_URI']); if (strpos($url, 'web/theme/wp/')) { $last_crumb_index = count( $crumbs ) - 1; $crumbs[ $last_crumb_index ][0] = 'wp theme'; } return $crumbs; }, 10, 2 );
But I don’t know how to change the “id”?
Hello,
You can use the following filter to update the ID in the Schema:
add_filter( 'rank_math/snippet/breadcrumb', function( $entity ) { $url = home_url($_SERVER['REQUEST_URI']); $last_crumb_index = count( $entity['itemListElement'] ) - 1; if (strpos($url, 'web/theme/wp/')) { $entity['itemListElement'][$last_crumb_index]['item']['@id'] = 'id you want to use'; //replace with the ID you want to use } return $entity; });
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thank you, it worked, just is it possible to combine these codes to make them smaller?
Hello,
Yes, you can combine the code snippets to streamline your customizations for both breadcrumb names and IDs.
Here’s how you could combine both adjustments into a single function called
$last_crumb_index
:add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs ) { $url = home_url($_SERVER['REQUEST_URI']); if (strpos($url, 'web/theme/wp/')) { $last_crumb_index = count( $crumbs ) - 1; // Update the breadcrumb name $crumbs[$last_crumb_index][0] = 'wp theme'; } return $crumbs; }, 10, 1 ); add_filter( 'rank_math/snippet/breadcrumb', function( $entity ) { $url = home_url($_SERVER['REQUEST_URI']); if (strpos($url, 'web/theme/wp/')) { $last_crumb_index = count( $entity['itemListElement'] ) - 1; // Update the ID for the last breadcrumb item $entity['itemListElement'][$last_crumb_index]['item']['@id'] = 'id you want to use'; //replace with the ID you want to use } return $entity; });
Remember to replace ‘id you want to use’ with the actual ID you want to assign to the last breadcrumb item.
We hope that helps, and please don’t hesitate to get in touch if you have any other questions.
Thank you.
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.
The ticket ‘Breadcrumb in category page’ is closed to new replies.