-
I have a recipe blog.
Can I choose category to exclude Rank Math Schema for structured data?
-
Hello,
Thank you for contacting Rank Math and bringing your concern to our attention.
Can you please confirm if you want a specific category to remove Schema? Or, if you want to remove Schema from all categories.
In order to exclude all categories from Schema, please head over to WordPress Dashboard > Rank Math > Titles & Meta > Category > Remove Snippet data and enable that option.
If you want to remove Schema from a specific category, please try adding the following filter in your WordPress site:
add_filter('rank_math/json_ld', function ($data, $jsonld) { if (is_category('category-slug')) { //replace 'category-slug' with the slug of your category return []; } return $data; }, 99, 2);
Here’s how you can add filter/hooks to your site:
https://rankmath.com/kb/wordpress-hooks-actions-filters/Let us know how it goes. Looking forward to helping you.
Thank you.
I added this code to rank-math.php file.
add_filter(‘rank_math/json_ld’, function ($data, $jsonld) {
if (is_category(‘antipasti’, ‘contorni’, ‘creme’, ‘dolci’, ‘guide’, ‘primi-piatti’, ‘salse-e-sughi’, ‘secondi-piatti’, )) { //replace ‘category-slug’ with the slug of your category
return [];
}
return $data;
}, 99, 2);But I did analysis with validator.schema.org and scheda is always there.
For example:
https://www.ricetteromane.it/primi-piatti/riso-e-lenticchie-alla-romana/
Did I make some wrong or do it need some time to take delete?
Hello,
Did I make some wrong or do it need some time to take delete?
The changes should take effect instantly. As the code you’ve shared wasn’t correct properly, that didn’t work.
The code I’ve shared above, only works for a specific category. To exclude multiple categories, please replace to code above with the following one. That should work for you.
add_filter('rank_math/json_ld', function ($data, $jsonld) { if ( is_category( array( 'antipasti', 'contorni', 'creme', 'dolci', 'guide', 'primi-piatti', 'salse-e-sughi', 'secondi-piatti' ) ) ) { //add category slugs return []; } return $data; }, 99, 2);
Let us know how it goes. Looking forward to helping you.
Thank you.
I put this at the beginning of file functions.php. Perhaps is location wrong?
[link moved to sensitive data section]
Hello,
You may add it anywhere in the file, but the best practice to add filters/hooks to your site is to put them at the bottom of your
funcitons.php
file.Hope that helps.
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 ‘Exclude category’ is closed to new replies.