Skip to content

Shortcodes: fix recipe time display to be compatible with Schema.org#7130

Merged
eliorivero merged 1 commit intoupdate/recipe-shortcode-wpcom-mergefrom
fix/recipe-time-schema
May 24, 2017
Merged

Shortcodes: fix recipe time display to be compatible with Schema.org#7130
eliorivero merged 1 commit intoupdate/recipe-shortcode-wpcom-mergefrom
fix/recipe-time-schema

Conversation

@jeherve
Copy link
Copy Markdown
Member

@jeherve jeherve commented May 5, 2017

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:

  • 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.

Reported here:
https://wordpress.org/support/topic/recipe-shortcode-lacks-css-class/

Testing instructions:

  • Insert a recipe in a new post, by following the instructions here. Provide a time attribute in your shortcode.
  • Publish your post.
  • Run your post through Google's Rich Snippets testing tool and make sure no errors are returned. Pay extra attention to warnings about time; there shouldn't be any. You will see some other warnings but those are okay for now.

Proposed changelog entry for your changes:

  • Shortcodes: fix recipe time display to be compatible with Schema.org, so your recipes' previews can appear in Google search results.

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.
@jeherve jeherve added [Feature] Shortcodes / Embeds [Pri] Normal [Status] Needs Review This PR is ready for review. Enhancement Changes to an existing feature — removing, adding, or changing parts of it labels May 5, 2017
@jeherve jeherve self-assigned this May 5, 2017
@jeherve jeherve requested a review from sarahmonster May 5, 2017 14:02
Copy link
Copy Markdown
Contributor

@sarahmonster sarahmonster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels May 16, 2017
@eliorivero eliorivero merged commit 1542c17 into update/recipe-shortcode-wpcom-merge May 24, 2017
@eliorivero eliorivero deleted the fix/recipe-time-schema branch May 24, 2017 15:01
@eliorivero eliorivero removed the [Status] Ready to Merge Go ahead, you can push that green button! label May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Shortcodes / Embeds [Pri] Normal Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants