diff --git a/class.jetpack.php b/class.jetpack.php index f5a574f8b3bb..aeef45b5a553 100644 --- a/class.jetpack.php +++ b/class.jetpack.php @@ -666,6 +666,7 @@ function( $callable ) { * 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 cc60770f4fa4..1a7617a0c115 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. @@ -32,11 +33,16 @@ function jetpack_og_tags() { return; } + $is_amp_response = ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ); + // Disable the widont filter on WP.com to avoid stray  s. $disable_widont = remove_filter( 'the_title', 'widont' ); - $og_output = "\n\n"; - $tags = array(); + $og_output = "\n"; + if ( ! $is_amp_response ) { // Because AMP optimizes the order or the nodes in the head. + $og_output .= "\n"; + } + $tags = array(); /** * Filter the minimum width of the images used in Jetpack Open Graph Meta Tags. @@ -287,7 +293,11 @@ function jetpack_og_tags() { } } } - $og_output .= "\n\n"; + + if ( ! $is_amp_response ) { // Because AMP optimizes the order or the nodes in the head. + $og_output .= "\n"; + } + $og_output .= "\n"; // This is trusted output or added by a filter. echo $og_output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped }