-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 AMP theme support #1286
base: master
Are you sure you want to change the base?
Add AMP theme support #1286
Conversation
functions.php
Outdated
@@ -24,6 +24,10 @@ function _s_setup() { | |||
*/ | |||
load_theme_textdomain( '_s', get_template_directory() . '/languages' ); | |||
|
|||
add_theme_support( 'amp', array( | |||
'comments_live_list' => true, | |||
) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naturally this shouldn't be merged as-is into master
. It would need to be opt-in by the theme developer.
I manually applied the changes to |
functions.php
Outdated
/** | ||
* Enqueue scripts. | ||
* | ||
* This short-circuits in AMP because custom scripts are not allowed. There is are AMP equivalents provided elsewhere. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/is are/are/
header.php
Outdated
[aria-expanded]="siteNavigationMenu.expanded ? 'true' : 'false'" | ||
> | ||
<?php esc_html_e( 'Primary Menu', '_s' ); ?> | ||
</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be indented.
header.php
Outdated
type="checkbox" | ||
hidden | ||
on="change:AMP.setState( { siteNavigationMenu: { expanded: event.checked } } )" | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hidden checkbox is far from ideal. It's mainly here because AMP doesn't yet support a toggleClass
action. See ampproject/amphtml#1032
The mess I had originally proposed for using a |
comments.php
Outdated
@@ -58,8 +67,23 @@ | |||
</ol><!-- .comment-list --> | |||
|
|||
<?php | |||
if ( _s_using_amp_live_list_comments() ) { | |||
add_filter( 'navigation_markup_template', '_s_add_amp_live_list_pagination_attribute' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little awkward. It would be preferable if AMP allowed for a nav
element (or role="navigation"
) instead of requiring an element with a custom pagination
attribute.
I didn't see an issue for AMP in Couple of question:
|
Thanks!
I don't think this decision has been made. However, in the same way that _s supports Jetpack and WooCommerce, it would seem logical to also support AMP.
See #1286 (comment). You're right that it should be opt-in. Maybe that looks like |
Thank you @westonruter for the pull request. It is nice to see what needs to be done on a themes side to make it compatable with the AMP Plugin.
As WordPress.com supports AMP and _s is used as a base for WordPress.com themes then it may be logical. I don't think it is logical for themes built by the community for clients and WordPress.org. Jetpack support can be easily be removed be deleting the If we were to add AMP support I would like to see easily removable.
|
[aria-expanded]="siteNavigationMenu.expanded ? 'true' : 'false'" | ||
<?php endif; ?> | ||
> | ||
<?php esc_html_e( 'Primary Menu', '_s' ); ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not figure out what the button is for. Is it for the mobile menu?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. If you resize the window to the mobile breakpoint then this button appears.
@grappler I've simplified the PR by removing the Also, I've removed |
Note that WP Rig has similar built-in AMP support now as well. |
This is an exploration into adding
amp
theme support to Underscores. This new theme support flag is being introduced in v0.7 of the AMP plugin._s_is_amp()
conditional function to check whether or not the response is being served as AMP .navigation.js
. Uses the:focus-within
peudo class instead of thefocus
class which was added via JS. This pseudo-class is supported by all browsers other than IE/Edge, and it ensures the submenu items are accessible even when JS is disabled. Also, amp-bind is used to manage the toggled state of the navigation menu on mobile. To get amp-bind to work, the togglebutton
has to be switched over to a button-like label which is connected to a hidden checkbox.skip-link-focus-fix.js
since it is not allowed in AMP and it is only needed by IE11 anyway.Adds support for usingamp-live-list
for the comment list, allowing new comments to be added to the page without reloading. A refresh time of 60 seconds is used by default. A_s_using_amp_live_list_comments()
conditional is added to check whetheramp-live-list
should be used in the template.meta[viewport]
is updated to add the AMP-requiredminimum-scale=1
value.With these changes applied to a theme, a vanilla WordPress install with the AMP plugin active can generate responses that do not trigger any AMP validation errors.
For more details on changes coming in AMP v0.7, see the RC1 release post. See also another full example theme which implements
amp
theme support, and a WordPress install that has the theme active.