Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add head metadata support for AMP Stories via amp_story_head action #13446

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
9 changes: 8 additions & 1 deletion frontend/schema/class-schema-article.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 );
}
Expand Down