This repository has been archived by the owner on Sep 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 865
/
enqueue-scripts.php
71 lines (53 loc) · 2.69 KB
/
enqueue-scripts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Enqueue all styles and scripts
*
* Learn more about enqueue_script: {@link https://codex.wordpress.org/Function_Reference/wp_enqueue_script}
* Learn more about enqueue_style: {@link https://codex.wordpress.org/Function_Reference/wp_enqueue_style }
*
* @package FoundationPress
* @since FoundationPress 1.0.0
*/
// 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 ) {
$filename_split = explode( '.', $filename );
$dir = end( $filename_split );
$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 = array();
}
if ( array_key_exists( $filename, $manifest ) ) {
return $manifest[ $filename ];
}
return $filename;
}
endif;
if ( ! function_exists( 'foundationpress_scripts' ) ) :
function foundationpress_scripts() {
// Enqueue the main Stylesheet.
wp_enqueue_style( 'main-stylesheet', get_stylesheet_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' );
// CDN hosted jQuery placed in the header, as some plugins require that jQuery is loaded in the header.
wp_enqueue_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '3.2.1', false );
// Deregister the jquery-migrate version bundled with WordPress.
wp_deregister_script( 'jquery-migrate' );
// CDN hosted jQuery migrate for compatibility with jQuery 3.x
wp_register_script( 'jquery-migrate', '//code.jquery.com/jquery-migrate-3.0.1.min.js', array('jquery'), '3.0.1', false );
// Enqueue jQuery migrate. Uncomment the line below to enable.
// wp_enqueue_script( 'jquery-migrate' );
// Enqueue Foundation scripts
wp_enqueue_script( 'foundation', get_stylesheet_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 need FontAwesome.
//wp_enqueue_script( 'fontawesome', 'https://use.fontawesome.com/5016a31c8c.js', array(), '4.7.0', true );
// Add the comment-reply library on pages where it is necessary
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'foundationpress_scripts' );
endif;