Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

AMP compatibility #155

Closed

Conversation

scottblackburn
Copy link

@scottblackburn scottblackburn commented Oct 18, 2018

This is just a start on #94 , I will keep working on this PR as the theme develops to check the theme is AMP compatible. These changes just resolve some AMP validation issues popping up in the validation checker.

  • Adds twentynineteen_amp_enabled() function to check whether response is being served as AMP and plugin is enabled.
  • Don't enqueue skip-link-focus-fix.js on AMP responses since it is not allowed in AMP.
  • Conditional added around viewport meta tag as minimum-scale=1 is required in AMP but probably not desirable in non-AMP cases.

Fixes #94.

@kjellr kjellr added the enhancement New feature or request label Oct 18, 2018
functions.php Outdated
// Don't include js on AMP endpoints.
if ( ! twentynineteen_amp_enabled ) {
wp_enqueue_script( 'twentynineteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
}
Copy link
Member

Choose a reason for hiding this comment

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

This will need to change as of #47.

functions.php Outdated
@@ -117,7 +125,10 @@ function twentynineteen_content_width() {
function twentynineteen_scripts() {
wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri() );

wp_enqueue_script( 'twentynineteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
// Don't include js on AMP endpoints.
if ( ! twentynineteen_amp_enabled ) {
Copy link
Member

Choose a reason for hiding this comment

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

Missing parens on the function call.

header.php Show resolved Hide resolved
functions.php Outdated
/**
* Check if AMP plugin is enabled and if AMP endpoint.
*/
function twentynineteen_amp_enabled() {
Copy link
Member

Choose a reason for hiding this comment

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

In WP Rig this would be called twentynineteen_is_amp(). I think that is better than ...amp_enabled because your site may have AMP enabled even though it is not being served at the moment, as in the case of paired mode or if you opt-out of AMP for a given post.

https://github.com/wprig/wprig/blob/d8d9cca76027b3057d4df2ce7cc3bd3101172281/dev/inc/template-tags.php#L10-L20

* thus it does not warrant having an entire dedicated blocking script being loaded.
*
*/
function _twentynineteen_skip_link_focus_fix() {
Copy link
Member

Choose a reason for hiding this comment

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

This change shouldn't be included yet. It's dependent on #47. Also, once/if that PR is merged, this function will then need the is_amp as seen in the WP Rig PR: wprig/wprig#139

Copy link
Author

Choose a reason for hiding this comment

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

@westonruter should we just revert back to the previous for now until #47 is merged?

Copy link
Member

Choose a reason for hiding this comment

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

yes

@@ -14,7 +14,7 @@
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
Copy link
Member

Choose a reason for hiding this comment

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

I've opened a separate PR just for this one change: #199

@allancole
Copy link
Collaborator

We ended up not adding explicit support for AMP to this theme. To do this properly there needs to be a method to enqueue scripts asynchronously (async) which is an old /core problem that still needs to be sorted out. As an alternative, I suggested installing the latest version of the AMP plugin, by XWP and @westonruter :-) : https://wordpress.org/plugins/amp/.

See: #94

Since we're closing out this repo to move the theme development fully to the Core Trac, I'm going to close this issue. Thanks!

@allancole allancole closed this Jan 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable AMP Compatibility
4 participants