Shortcodes: fix recipe time display to be compatible with Schema.org#7130
Merged
eliorivero merged 1 commit intoupdate/recipe-shortcode-wpcom-mergefrom May 24, 2017
Merged
Conversation
We previously displayed the total recipe time as the user provided it in the shortcode. While that works on the site, that format isn't compatible with Schema.org. Search engines relying on Schema.org to display recipe previews expect the recipe time to use ISO 8601 formatted duration interval. This commit does 2 things: - It adds a new shared function allowing you to convert any user-inputted duration into ISO 8601 formatted duration. - It uses the shared function to output a new `time` tag in the recipe output, where that formatted duration is added as a datetime attribute.
sarahmonster
approved these changes
May 16, 2017
Contributor
sarahmonster
left a comment
There was a problem hiding this comment.
I tested this with the example provided on the WordPress.com docs time="2hr 30mins" and it wasn't able to convert it, giving a warning when I ran it through the structured data testing tool.
The time formats accepted by strtotime seem to be geared more toward static times than to durations—so it can handle, for instance "15 min" or "15 minutes" but not "2h15". This is definitely a good start, but we may want to look at ways to make this more resilient and more accepting of a variety of formats for a future iteration—especially if we could see how this field is actually being used by people.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed in this Pull Request:
This PR is set to be merged into
update/recipe-shortcode-wpcom-merge, as it relies on the changes proposed in #7125. I'll update the base branch if #7125 gets merged.We previously displayed the total recipe time as the user provided it in the shortcode.
While that works on the site, that format isn't compatible with Schema.org.
Search engines relying on Schema.org to display recipe previews expect the recipe time to use ISO 8601 formatted duration interval.
This PR does 2 things:
timetag in the recipe output, where that formatted duration is added as adatetime attribute.
Reported here:
https://wordpress.org/support/topic/recipe-shortcode-lacks-css-class/
Testing instructions:
timeattribute in your shortcode.Proposed changelog entry for your changes: