I’m trying to fix a schema issue on my WooCommerce site. I disabled RankMath’s auto-generated schema for collection pages because of a problem with aggregate ratings on product snippets. To solve this, I added custom schema using HFCM.
The problem is that the custom schema I added for the category collection also applies to all the products in that category, which I don’t want. I’m looking for a way to make sure the schema is only on the category page, not the individual product pages.
Does anyone have advice on how to fix this? Are there better plugins or a workaround for this issue? Thanks for any help!
You might want to check how HFCM is targeting the schema. It could be applying the code globally to all pages instead of just the category page. Try adding conditions based on the URL structure or page type in HFCM settings. For example, you could limit the schema to pages with ‘/category/’ in the URL.
Have you tried using a plugin like WPCode? It lets you add custom scripts with more precise targeting options. You can choose to run scripts only on specific page types, like category pages. That might solve your issue.
Another approach could be using RankMath’s filters to modify the schema output. You can use their hooks to disable schema for specific pages or categories. It’s more technical, but it works if you’re familiar with PHP.
I faced a similar issue before. What worked for me was adding a condition in the schema code itself. Check if the page is a category page using is_category() in your PHP code and only load the schema if that condition is true.
Kane said: @Benwillison3
Thanks for the tip. I’ll try adding that condition. Did you add it directly in the theme’s functions file?
Yes, I added it in the functions.php file of my child theme. Just make sure to back up your site before making changes. Let me know if you need help with the code!
If you’re using HFCM, try duplicating the schema and setting one for category pages and another for products with specific targeting. It’s a bit of extra work but can help isolate where the schema shows up.