Hello,
Yes, it is possible to remove the Organization Schema from posts in specific categories. You can achieve this by using a code snippet. Here is the code snippet you can use:
add_filter('rank_math/json_ld', function ($data, $jsonld) {
if (is_product_category('category-slug')) {
return [];
}
return $data;
}, 99, 2);
Replace ‘category-slug’ with the slug of the product category from which you want to remove the Schema. You can also add multiple slugs if you want to remove Schema from multiple categories by extending this code.
If you have any further questions or need assistance, feel free to reach out to our support team here. We are always here to help.
Sources:
Remove Organization Schema from Your Website » Rank Math
Removing Schema From Your Posts & Pages » Rank Math
Remove All Schema from Product Category Pages » Rank Math
And if I want remove category or for example some categorys?
Thanks.
Hello,
Thank you for contacting us and bringing your concern to our attention.
You can use the following filter on your website and see if that works for you:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
global $post;
$categories = get_the_terms( $post->ID, 'category' );
// Replace 'category-slug-1', 'category-slug-2' with your actual category slugs
$exclude_categories = array( 'category-slug-1', 'category-slug-2');
if ( is_array( $categories ) && array_intersect( $exclude_categories, wp_list_pluck( $categories, 'slug' ) ) && isset( $data['publisher'] ) ) {
unset( $data['publisher'] );
}
return $data;
}, 99, 2);
Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Let us know how it goes. Looking forward to helping you.
Thank you.
Hi,
Thanks, But I am also referring to the posts included in that category.
Hello,
Thank you for your patience.
Please update the filter to this one and check again the posts under the category you have defined:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
global $post;
$categories = get_the_terms( $post->ID, 'category' );
// Replace 'category-slug-1', 'category-slug-2' with your actual category slugs
$exclude_categories = array( 'category-slug-1', 'category-slug-2');
if ( is_array( $categories ) && array_intersect( $exclude_categories, wp_list_pluck( $categories, 'slug' ) ) && isset( $data['publisher'] ) ) {
$catPost = get_posts(array($exclude_categories));
foreach ($catPost as $post) {
unset( $data['publisher'] );
}
unset( $data['publisher'] );
}
return $data;
}, 99, 2);
If it’s still not working, please share the actual code you’re using and the sample post where we can check the schema.
Looking forward to helping 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.