Browse Source

Enqueue fixed header spacing JS only for non AMP endpoints

Deepak Lalwani 5 years ago
parent
commit
ba03d55380
1 changed files with 11 additions and 2 deletions
  1. 11 2
      rockfield/functions.php

+ 11 - 2
rockfield/functions.php

@@ -171,8 +171,10 @@ function rockfield_scripts() {
 	// enqueue child RTL styles
 	// enqueue child RTL styles
 	wp_style_add_data( 'rockfield-style', 'rtl', 'replace' );
 	wp_style_add_data( 'rockfield-style', 'rtl', 'replace' );
 
 
-	// enqueue header spacing JS
-	wp_enqueue_script('rockfield-fixed-header-spacing', get_stylesheet_directory_uri() . '/js/fixed-header-spacing.js', array(), wp_get_theme()->get( 'Version' ), true );
+	if ( ! rockfield_is_amp() ) {
+		// enqueue header spacing JS.
+		wp_enqueue_script( 'rockfield-fixed-header-spacing', get_stylesheet_directory_uri() . '/js/fixed-header-spacing.js', array(), wp_get_theme()->get( 'Version' ), true );
+	}
 
 
 }
 }
 add_action( 'wp_enqueue_scripts', 'rockfield_scripts', 99 );
 add_action( 'wp_enqueue_scripts', 'rockfield_scripts', 99 );
@@ -186,3 +188,10 @@ function rockfield_editor_styles() {
 	wp_enqueue_style( 'rockfield-editor-fonts', rockfield_fonts_url(), array(), null );
 	wp_enqueue_style( 'rockfield-editor-fonts', rockfield_fonts_url(), array(), null );
 }
 }
 add_action( 'enqueue_block_editor_assets', 'rockfield_editor_styles' );
 add_action( 'enqueue_block_editor_assets', 'rockfield_editor_styles' );
+
+/**
+ * Checks whether the endpoint is AMP.
+ */
+function rockfield_is_amp() {
+	return ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() );
+}