Skip to content

Commit

Permalink
Introduce amp_story_head action
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Aug 17, 2019
1 parent 3362b66 commit f911cb2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
31 changes: 31 additions & 0 deletions includes/class-amp-story-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,37 @@ public static function register() {

add_action( 'wp_enqueue_scripts', [ __CLASS__, 'add_custom_stories_styles' ] );

add_action( 'amp_story_head', 'rel_canonical' );
add_action( 'amp_story_head', 'amp_add_generator_metadata' );
add_action( 'amp_story_head', 'wp_enqueue_scripts' );
add_action( 'amp_story_head', 'rel_canonical' );

// @todo Create methods/functions for some of these.
add_action(
'amp_story_head',
static function() {
// @todo Eliminate in favor of adding via post-processor.
echo amp_get_boilerplate_code(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
},
PHP_INT_MAX
);
add_action(
'amp_story_head',
function() {
// See _wp_render_title_tag().
echo '<title>' . esc_html( wp_get_document_title() ) . '</title>' . "\n";
}
);
add_action(
'amp_story_head',
function() {
// @todo Temporary until sanitizer automatically supplies runtime.
wp_scripts()->do_items( [ 'amp-runtime' ] ); // @todo Duplicate with AMP_Theme_Support::enqueue_assets().

wp_styles()->do_items();
}
);

// Remove unnecessary settings.
add_filter( 'block_editor_settings', [ __CLASS__, 'filter_block_editor_settings' ], 10, 2 );

Expand Down
17 changes: 8 additions & 9 deletions includes/templates/single-amp_story.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@

the_post();

$metadata = amp_get_schemaorg_metadata();
?>
<!DOCTYPE html>
<html amp <?php language_attributes(); ?>>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<title><?php echo esc_html( wp_get_document_title() ); ?></title>

<?php
wp_enqueue_scripts();
wp_scripts()->do_items( [ 'amp-runtime' ] ); // @todo Duplicate with AMP_Theme_Support::enqueue_assets().
wp_styles()->do_items();
/**
* Prints scripts or data in the head tag on the front end.
*
* @since 1.2.1
*/
do_action( 'amp_story_head' );
?>
<?php rel_canonical(); ?>
<?php amp_add_generator_metadata(); ?>
<script type="application/ld+json"><?php echo wp_json_encode( $metadata, JSON_UNESCAPED_UNICODE ); ?></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>
<?php
$metadata = amp_get_schemaorg_metadata();
if ( isset( $metadata['publisher']['logo']['url'] ) ) {
$publisher_logo_src = $metadata['publisher']['logo']['url'];
} elseif ( isset( $metadata['publisher']['logo'] ) && is_string( $metadata['publisher']['logo'] ) ) {
Expand Down

0 comments on commit f911cb2

Please sign in to comment.