Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created September 13, 2019 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/0d5635dac1178af448e417a77b8494ad to your computer and use it in GitHub Desktop.
Save westonruter/0d5635dac1178af448e417a77b8494ad to your computer and use it in GitHub Desktop.
diff --git a/core/modules/class-wp-smush-lazy-load.php b/core/modules/class-wp-smush-lazy-load.php
index bf5a447..d612bfc 100644
--- a/core/modules/class-wp-smush-lazy-load.php
+++ b/core/modules/class-wp-smush-lazy-load.php
@@ -60,11 +60,6 @@ class WP_Smush_Lazy_Load extends WP_Smush_Module {
return;
}
- // Skip AMP pages.
- if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
- return;
- }
-
// Load js file that is required in public facing pages.
add_action( 'wp_head', array( $this, 'add_inline_styles' ) );
@@ -92,13 +87,22 @@ class WP_Smush_Lazy_Load extends WP_Smush_Module {
}
}
+ /**
+ * Determine whether it is an AMP page.
+ *
+ * @return bool Whether AMP.
+ */
+ private function is_amp() {
+ return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() );
+ }
+
/**
* Add inline styles at the top of the page for pre-loaders and effects.
*
* @since 3.2.0
*/
public function add_inline_styles() {
- if ( ! $this->options['animation']['selected'] ) {
+ if ( ! $this->options['animation']['selected'] || $this->is_amp() ) {
return;
}
@@ -160,6 +164,10 @@ class WP_Smush_Lazy_Load extends WP_Smush_Module {
* @since 3.2.0
*/
public function enqueue_assets() {
+ if ( $this->is_amp() ) {
+ return;
+ }
+
$in_footer = isset( $this->options['footer'] ) ? $this->options['footer'] : true;
wp_enqueue_script(
@@ -241,6 +249,10 @@ lazySizesConfig.loadMode = 1;"; // Page is optimized for fast onload event.
* @return string
*/
public function parse_image( $src, $image ) {
+ if ( $this->is_amp() ) {
+ return $image;
+ }
+
/**
* Filter to skip a single image from lazy load.
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment