Reviewed & tested by the community
Project:
Structured Data (JSON+LD Rich Snippets)
Version:
7.x-1.0
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
30 Jun 2017 at 15:29 UTC
Updated:
17 Nov 2017 at 00:30 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
apmsooner commentedComment #3
apmsooner commentedExample using new alter to update structured data. Works for me....
Comment #4
ajayg commentedSince you have started with 'Recipe Type' would it be possible to show the complete all fields required by "Recipes" ? Showing one field is proof of concept, but would be useful to see the hook can handle multiple fields typically required to support a content type. What I am trying to figure out the hook is flexible and does not choke as you add new structured data types.
Comment #5
apmsooner commentedHere is an example of how i'm using the alter hook. Note that some things you have setup as defaults are assumed at only the site level so i'm unsetting those as they will produce errors when testing in the google structured data tool for recipes. For recipe, an image is required per finding out via testing through the structured data tool. An alter hook allows me to specify what i need and don't need but i would recommend probably removing the stuff like logo, address, etc... from your implementation as it seems to only be pertinent to the front page? Anyhow, i have some extra code here that is grabbing my ingredient data but i think you can get an idea from below...
Comment #6
apmsooner commentedI should add... technically i shouldn't be trying to output structured data at all if an image doesn't exist for my recipe since it is required but the code above was just what i was playing around with to get basic recipe context setup. Here is an example recipe per google as well although not all those fields are required in order to work. I havn't found a specific document outlining minimum requirements per @type so i've just been relying on what the testing tool outputs in its results.
Comment #7
apmsooner commentedOh found it! Although in this link it says image isn't required, the testing tool produced an error when i tried to test structured data without one... could be a bug in the tool maybe. Here is for recipe and the sidebar shows list of other types which may help explain further: https://developers.google.com/search/docs/data-types/recipes
Comment #8
alasda commentedApplied patch. Created custom hook in utility module. json+ld page output modified as expected.
Tested and working.
Comment #9
alasda commented