Hello @vtrn,
Thank you for your query and we are so sorry about the trouble this must have caused.
The PHP Warning that you are seeing is caused by an invalid schema markup. If you have added a custom schema for a particular page, then you can use the bulk action to add the default schema on this page and Rank Math will automatically remove all other invalid schema from there: https://rankmath.com/kb/bulk-editing-in-rank-math/#set-schema-markup-to-default-type and then, you can add back the correct schema again and see if that resolves the issue.
If it doesn’t, let us know here so we can debug this issue further.
Looking forward to helping you.
Thread Starter
vtrn
(@vtrn)
Hi, I found the problem.
I have disabled the schema of products belonging to a specific category using the following code:
add_filter( 'rank_math/snippet/rich_snippet_product_entity', function ($data) {
$term_ids = array();
$product_cats = wp_get_post_terms(get_the_ID(), 'product_cat');
foreach ($product_cats as $product_cat) {
$term_ids[] = $product_cat->term_id;
}
$exclude_category_ids = array( 1665, 1668);
if (array_intersect($exclude_category_ids, $term_ids)) {
return false;
}
return $data;
} );
And when I open a product in these categories
This error occurs
How can I avoid this error?
Hello @vtrn,
That filter is used to modify the Schema data. You shouldn’t use that to remove a Schema type completely. Please use the following filter instead:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) { if(is_product()) { $term_ids = array(); $product_cats = wp_get_post_terms(get_the_ID(), 'product_cat'); foreach ($product_cats as $product_cat) { $term_ids[] = $product_cat->term_id; } $exclude_category_ids = array( 1665, 1668,); if (array_intersect($exclude_category_ids, $term_ids)) { unset($data['richSnippet']); } } return $data; }, 99, 2);
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.