diff --git a/library/enqueue-scripts.php b/library/enqueue-scripts.php index 28cacde00..209810698 100644 --- a/library/enqueue-scripts.php +++ b/library/enqueue-scripts.php @@ -10,45 +10,33 @@ */ -if ( ! function_exists( 'foundationpress_scripts' ) ) : - function foundationpress_scripts() { - - // Check to see if rev-manifest exists for CSS and JS static asset revisioning - //https://github.com/sindresorhus/gulp-rev/blob/master/integration.md - function css_asset_path($filename) { - $manifest_path = dirname(dirname(__FILE__)) . '/dist/assets/css/rev-manifest.json'; - - if (file_exists($manifest_path)) { - $manifest = json_decode(file_get_contents($manifest_path), TRUE); - } else { - $manifest = []; - } - - if (array_key_exists($filename, $manifest)) { - return $manifest[$filename]; - } - - return $filename; - } - - function js_asset_path($filename) { - $manifest_path = dirname(dirname(__FILE__)) . '/dist/assets/js/rev-manifest.json'; - - if (file_exists($manifest_path)) { - $manifest = json_decode(file_get_contents($manifest_path), TRUE); - } else { - $manifest = []; - } +// Check to see if rev-manifest exists for CSS and JS static asset revisioning +//https://github.com/sindresorhus/gulp-rev/blob/master/integration.md + +if ( ! function_exists( 'foundationpress_asset_path' ) ) : +function foundationpress_asset_path( $filename ) { + $dir = end( explode ( '.' , $filename) ); + $manifest_path = dirname( dirname(__FILE__) ) . '/dist/assets/' . $dir . '/rev-manifest.json'; + + if ( file_exists($manifest_path ) ) { + $manifest = json_decode( file_get_contents( $manifest_path ), TRUE); + } else { + $manifest = []; + } + + if ( array_key_exists( $filename, $manifest) ) { + return $manifest[$filename]; + } + return $filename; +} +endif; - if (array_key_exists($filename, $manifest)) { - return $manifest[$filename]; - } - return $filename; - } +if ( ! function_exists( 'foundationpress_scripts' ) ) : + function foundationpress_scripts() { // Enqueue the main Stylesheet. - wp_enqueue_style( 'main-stylesheet', get_template_directory_uri() . '/dist/assets/css/' . css_asset_path('app.css'), array(), '2.10.4', 'all' ); + wp_enqueue_style( 'main-stylesheet', get_template_directory_uri() . '/dist/assets/css/' . foundationpress_asset_path('app.css'), array(), '2.10.4', 'all' ); // Deregister the jquery version bundled with WordPress. wp_deregister_script( 'jquery' ); @@ -57,7 +45,7 @@ function js_asset_path($filename) { wp_enqueue_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '3.2.1', false ); // Enqueue Founation scripts - wp_enqueue_script( 'foundation', get_template_directory_uri() . '/dist/assets/js/' . js_asset_path('app.js'), array( 'jquery' ), '2.10.4', true ); + wp_enqueue_script( 'foundation', get_template_directory_uri() . '/dist/assets/js/' . foundationpress_asset_path('app.js'), array( 'jquery' ), '2.10.4', true ); // Enqueue FontAwesome from CDN. Uncomment the line below if you don't need FontAwesome. //wp_enqueue_script( 'fontawesome', 'https://use.fontawesome.com/5016a31c8c.js', array(), '4.7.0', true ); diff --git a/library/theme-support.php b/library/theme-support.php index ad18c3411..57d9eb7e2 100644 --- a/library/theme-support.php +++ b/library/theme-support.php @@ -41,7 +41,7 @@ function foundationpress_theme_support() { add_theme_support( 'wc-product-gallery-slider' ); // Add foundation.css as editor style https://codex.wordpress.org/Editor_Style - add_editor_style( 'dist/assets/css/app.css' ); + add_editor_style( 'dist/assets/css/' . foundationpress_asset_path('app.css')); } add_action( 'after_setup_theme', 'foundationpress_theme_support' );