From b9a8a161a48206753b5603688b1bf864022f8458 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 3 Sep 2019 12:12:48 -0700 Subject: [PATCH 1/3] Add head metadata support for AMP Stories via amp_story_head action --- frontend/class-frontend.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/class-frontend.php b/frontend/class-frontend.php index f797193d746..04003543a27 100644 --- a/frontend/class-frontend.php +++ b/frontend/class-frontend.php @@ -90,6 +90,7 @@ protected function __construct() { add_action( 'wp_head', array( $this, 'front_page_specific_init' ), 0 ); add_action( 'wp_head', array( $this, 'head' ), 1 ); + add_action( 'amp_story_head', array( $this, 'head' ), 1 ); // The head function here calls action wpseo_head, to which we hook all our functionality. add_action( 'wpseo_head', array( $this, 'debug_mark' ), 2 ); @@ -100,10 +101,13 @@ protected function __construct() { // Remove actions that we will handle through our wpseo_head call, and probably change the output of. remove_action( 'wp_head', 'rel_canonical' ); + remove_action( 'amp_story_head', 'rel_canonical' ); remove_action( 'wp_head', 'index_rel_link' ); remove_action( 'wp_head', 'start_post_rel_link' ); remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); + remove_action( 'amp_story_head', 'adjacent_posts_rel_link_wp_head' ); remove_action( 'wp_head', 'noindex', 1 ); + remove_action( 'amp_story_head', 'noindex', 1 ); // When using WP 4.4, just use the new hook. add_filter( 'pre_get_document_title', array( $this, 'title' ), 15 ); From c95fc457782d66881aa23ce820dfbf4513b5b850 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 6 Sep 2019 10:45:08 -0700 Subject: [PATCH 2/3] Let amp_story post type default to BlogPosting type --- frontend/schema/class-schema-webpage.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/schema/class-schema-webpage.php b/frontend/schema/class-schema-webpage.php index fee7049c543..f8ebf8174a2 100644 --- a/frontend/schema/class-schema-webpage.php +++ b/frontend/schema/class-schema-webpage.php @@ -150,6 +150,9 @@ private function determine_page_type() { case is_archive(): $type = 'CollectionPage'; break; + case is_singular( 'amp_story' ): + $type = 'BlogPosting'; + break; default: $type = 'WebPage'; } From ba929abcda8020508cf393d4635290f8e480680f Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Fri, 20 Sep 2019 11:05:22 +0100 Subject: [PATCH 3/3] Override article ld data using amp_get_schemaorg_metadata function --- frontend/schema/class-schema-article.php | 9 ++++++++- frontend/schema/class-schema-webpage.php | 3 --- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/schema/class-schema-article.php b/frontend/schema/class-schema-article.php index d5d865e9749..57117eaf2b7 100644 --- a/frontend/schema/class-schema-article.php +++ b/frontend/schema/class-schema-article.php @@ -73,6 +73,13 @@ public function generate() { $data = $this->add_keywords( $data ); $data = $this->add_sections( $data ); + // If using the amp plugin, use amp_get_schemaorg_metadata function to generate ld data and merge with article data. + if ( is_singular('amp_story') && function_exists( 'amp_get_schemaorg_metadata' ) ) { + $amp_metadata = amp_get_schemaorg_metadata(); + unset( $amp_metadata['@context'] ); + $data = wp_parse_args( $amp_metadata, $data ); + } + return $data; } @@ -93,7 +100,7 @@ public static function is_article_post_type( $post_type = null ) { * * @api string[] $post_types The post types for which we output Article. */ - $post_types = apply_filters( 'wpseo_schema_article_post_types', array( 'post' ) ); + $post_types = apply_filters( 'wpseo_schema_article_post_types', array( 'post', 'amp_story' ) ); return in_array( $post_type, $post_types ); } diff --git a/frontend/schema/class-schema-webpage.php b/frontend/schema/class-schema-webpage.php index f8ebf8174a2..fee7049c543 100644 --- a/frontend/schema/class-schema-webpage.php +++ b/frontend/schema/class-schema-webpage.php @@ -150,9 +150,6 @@ private function determine_page_type() { case is_archive(): $type = 'CollectionPage'; break; - case is_singular( 'amp_story' ): - $type = 'BlogPosting'; - break; default: $type = 'WebPage'; }