Demonstrate addition of AMP compatibility to the core bundled themes #307
Conversation
@westonruter does |
@rheinardkorf no, not as of v1.0-alpha. There is an admin screen for you to select the desired mode. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
This PR demonstrates how AMP compatibility can be added to the themes that are bundled with core, namely:
AMP_Core_Theme_Sanitizer
, but the code is useful in particular if you have forked a core theme and want to apply the changes to your theme. If you want to try out the changes, you should disable theAMP_Core_Theme_Sanitizer
in your install via:Also compare with AMP support added to Underscores: Automattic/_s#1286. The changes are also generally available in WP Rig.
Remember that custom JavaScript is not allowed in AMP, and the AMP plugin will sanitize all of it out to create a valid AMP response. Therefore, the baseline experience when enabling AMP on a theme is that it behaves as if JavaScript is disabled in the browser. Therefore, most of the work entailed is to progressively enhance a theme for AMP to restore features that were lost during the graceful degradation to AMP. These enhancements for AMP generally involve the use of modern CSS selectors (e.g.
:focus-within
), AMP components (e.g.amp-position-observer
), or AMP scripting viaamp-bind
.The changes applied to the core themes include:
is_amp()
function to wrap theis_amp_endpoint()
call, after the requisitefunction_exists()
check.minimum-scale=1
to themeta
viewport; remove redundant@viewport
CSS at-rule since redundant withmeta
and AMP doesn't allow it.amp-bind
to manage the expanded state of the (hamburger) nav menu on mobile.walker_nav_menu_start_el
PHP filter instead of via jQuery, and usingamp-bind
to manage the expanded state of the sub-menus.ul
.no-js
if not AMP since they will be shown in AMP.:hover
pseudo-class and via the JS-toggled.focus
classes, use the:focus-within
pseudo class to accomplish the same as.focus
(though note that it is not supported in IE/Edge).no-js
withjs
on thehtml
element. Custom JavaScript is not allowed in AMP so this script would be removed anyway.html5
: This script is only needed by IE8 and below, which has negligible marketshare now.skip-link-focus-fix
: Similarly, this script is only needed by IE11 which has a small marketshare, so it is not implemented in AMP.keyboard-image-navigation
: AMP does not provide a way to listen to keydown events.global
/functions
This largely for nav menus which are implemented in AMP via PHP filters and amp-bind. Fixed sidebar is approximated in AMP. There is no AMP implementation provided foronResizeARIA
orbelowEntryMetaClass
.Theme-specific changes include:
Twenty Fifteen
style.css
andadmin-bar.css
combine to be over 50KB even after the plugin does CSS tree-shaking.position:sticky
.Twenty Seventeen
blockquotes
using PHPthe_content
filter instead of using jQuery.AMP.scrollTo()
instead of requiring the jQuery scrollTo plugin.amp-position-observer
andamp-animation
. With this change the original nav menu can remain statically positioned in the document.background-fixed
class to HTML element in PHP since fixed background images are supported by most browsers. Likewise, addsvg
to HTML element instead ofno-svg
when in AMP since inline SVG is supported by most browsers.has-header-video
body class in PHP instead of JS.amp-img
andamp-video
.Examples