I'm have a custom archive page view for a custom post type working (both done with Toolset). Now I face the problem that, for each displayed post one each page of the archive, I would need to add some code to the <head> section of the page (Schema metadata).
I know how to do this for normal pages, but us there anyway to hook to that custom archive loop from a PHP function in my functions.php or whatever?
Hooking "into the loop" won't help because it is too late to add anything to the head, by the time WordPress gets to the loop it is already building the body.
You could use a plugin to add schema data to the head, but if doing it yourself you may want to use the wp_head hook so that you can add content to the head section. Your code would want to check you are on the relevant archive page before adding the relevant content.
The problem with wp_head and is_post_type_archive is that I would need to add schema to the head for each and every element of the query. AFAIK I can't do that there as I need to retrieve the data for each displayed post and put that in the head with JSON-LD. Am I missing something?
Although I'd prefer using JSON-LD I think the path of less resistance is going to be adding microdata to the templates, hehe! But wondering if there's a different option (not modifying theme templates) to make using JSON-LD a possibility.
I know it's not the typical use case for Toolset, but preferred to ask before implementing everything.
You would basically have to recreate iterating over the loop using wp_head because when the loop is actually iterated over the head is history already, it's too late to add to it.
So if you want the schema data to come from the posts which appear in the index themselves then I don't see any alternative to adding the schema attributes to the markup (the values for which you can generate using Toolset shortcodes if needed).