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 2 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
3 changes: 3 additions & 0 deletions frontend/schema/class-schema-webpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ private function determine_page_type() {
case is_archive():
$type = 'CollectionPage';
break;
case is_singular( 'amp_story' ):
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of having this in the yoast plugin, why not do this in the AMP plugin using the wpseo_schema_webpage_type filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because that filter is specific to Yoast. The AMP plugin doesn't generally have plugin-specific code. There was a bunch of Jetpack code but most of it has been moved to Jetpack.

Copy link
Contributor

Choose a reason for hiding this comment

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

So the plugin specific code lives in yoast / jetpack instead of the other way around?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. That's the scalable way to add AMP compatibly to the ecosystem, if thenesa and plugins take the responsibility of AMP compatibility.

$type = 'BlogPosting';
break;
default:
$type = 'WebPage';
}
Expand Down