Amp-wp: Allow plugins to add metadata to AMP Stories

Created on 5 Aug 2019  ·  7Comments  ·  Source: ampproject/amp-wp

  • I am optimizing my Story for Search & for Social using the Yoast plugin

  • When I publish a Story, it IS being crawled and being added to Search results when I optimize with the Yoast plugin. ✅

  • However, when I add my story to Slack or Social (Social/Share), it is not fetching the image or description. We think this is a bug. 😐
AMP Stories (obsolete) Enhancement

Most helpful comment

Probably what we should do here is introduce a new amp_story_head action which such plugins can use to target the injection of AMP markup into this template.

While doing this, we can remove hard-coded head code:

Aside: The v0.js and AMP boilerplate style should really be getting injected by the post-processor anyway

Sounds good to me!

All 7 comments

Please share the URL of the story.

Here is a link to an experimental story that was published... thanks!
https://cathibosco.com/stories/nikko/

Link to the archive page: https://cathibosco.com/stories/

The Schema.org metadata is:

{
    "@context": "http://schema.org",
    "@type": "BlogPosting",
    "author": {
        "@type": "Person",
        "name": "Cathi Bosco"
    },
    "dateModified": "2019-08-06T17:16:35+00:00",
    "datePublished": "2019-06-24T13:40:57+00:00",
    "headline": "Nikk\u014d T\u014dsh\u014d-g\u016b, Japan",
    "image": {
        "@type": "ImageObject",
        "height": 1600,
        "url": "https://cathibosco.com/wp-content/uploads/2019/06/Nikko-FI-cathi-bosco-1.png",
        "width": 1200
    },
    "mainEntityOfPage": "https://cathibosco.com/stories/nikko/",
    "publisher": {
        "@type": "Organization",
        "logo": {
            "@type": "ImageObject",
            "height": 1,
            "url": "https://cathibosco.com/wp-content/uploads/2019/01/cathibosco-design-logo-ux-design-leader.svg",
            "width": 1
        },
        "name": "Design + Business + Technology = UX Awesome!"
    }
}

For Google Search, I can see there is an error with the publisher logo image: the SVG format is not allowed.

image

See https://search.google.com/structured-data/testing-tool#url=https%3A%2F%2Fcathibosco.com%2Fstories%2Fnikko%2F

Now, Slack and other social providers are a different… story.

It appears Slack only supports Twitter and Facebook meta: https://api.slack.com/docs/message-link-unfurling#classic_unfurling

These would normally be added by Jetpack or Yoast, but in the AMP Story template (single-amp_story.php) we do not invoke wp_head() in order to prevent arbitrary theme/plugin code from interfering with the story format.

One option would be to manually create the Twitter and Facebook meta ourselves, but this would reinvent the wheel. We should rather rely on Jetpack or Yoast to do this.

Probably what we should do here is introduce a new amp_story_head action which such plugins can use to target the injection of AMP markup into this template. This would be similar to how WordPress has an embed_head action which fires in the Post Embed template.

While doing this, we can remove hard-coded head code:

https://github.com/ampproject/amp-wp/blob/d2971f2b8752ac88919f1d18c155f13c720d0e51/includes/templates/single-amp_story.php#L15-L24

And we can instead hook into this amp_story_head action instead. Then Jetpack or Yoast could output their own Schema.org metadata instead as well.

Aside: The v0.js and AMP boilerplate style should really be getting injected by the post-processor anyway (see also #1778).

Probably what we should do here is introduce a new amp_story_head action which such plugins can use to target the injection of AMP markup into this template.

While doing this, we can remove hard-coded head code:

Aside: The v0.js and AMP boilerplate style should really be getting injected by the post-processor anyway

Sounds good to me!

Once this is closed, PRs should be opened to Jetpack and Yoast. For example:

diff --git a/class.jetpack.php b/class.jetpack.php
index 346b85c6e..d85a99a77 100644
--- a/class.jetpack.php
+++ b/class.jetpack.php
@@ -657,6 +657,7 @@ class Jetpack {
         * They check for external files or plugins, so they need to run as late as possible.
         */
        add_action( 'wp_head', array( $this, 'check_open_graph' ),       1 );
+       add_action( 'amp_story_head', array( $this, 'check_open_graph' ),1 );
        add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ),     999 );
        add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 );

diff --git a/functions.opengraph.php b/functions.opengraph.php
index cc60770f4..75107ee2a 100644
--- a/functions.opengraph.php
+++ b/functions.opengraph.php
@@ -12,6 +12,7 @@
  */

 add_action( 'wp_head', 'jetpack_og_tags' );
+add_action( 'amp_story_head', 'jetpack_og_tags' );

 /**
  * Outputs Open Graph tags generated by Jetpack.

Opened Jetpack PR to add support for this: https://github.com/Automattic/jetpack/pull/13416

And support for Yoast has been drafted via https://github.com/Yoast/wordpress-seo/pull/13446

Was this page helpful?
0 / 5 - 0 ratings