You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 3, 2024. It is now read-only.
* Removing “min” suffix and associated structure; with sourcemaps there
is no need for this anymore
* `images-dist` now `images-optimize` to better explain what this
function does
* More and better comments, particularly in the assets-loading file
Copy file name to clipboardExpand all lines: gulpconfig.js
+3-4Lines changed: 3 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -53,14 +53,14 @@ module.exports = {
53
53
,chunks: {// Chunks are arrays of paths or globs matching a set of source files; this way you can organize a bunch of scripts that go together into pieces that can then be bundled (above)
54
54
// The core chunk is loaded no matter what; put essential scripts that you want loaded by your theme in here
55
55
core: [
56
-
modules+'timeago/jquery.timeago.js'
56
+
modules+'timeago/jquery.timeago.js'// The modules directory contains packages downloaded via npm
57
57
,src+'js/responsive-menu.js'
58
58
,src+'js/core.js'
59
59
]
60
60
// The pageloader chunk provides an example of how you would add a user-configurable feature to your theme; you can delete this if you wish
61
61
// Have a look at the `src/inc/assets.php` to see how script bundles could be conditionally loaded by a theme
62
62
,pageloader: [
63
-
modules+'html5-history-api/history.js'// The modules directory contains packages downloaded via npm
src: [src+'js/**/*.js']// Linting checks the quality of the code; we only lint custom scripts, not those under the various modules, so we're relying on the original authors to ship quality code
Copy file name to clipboardExpand all lines: src/inc/assets.php
+23-19Lines changed: 23 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,60 +1,64 @@
1
1
<?php// ==== ASSETS ==== //
2
2
3
3
// Now that you have efficiently generated scripts and stylesheets for your theme, how should they be integrated?
4
-
// This file walks you through the approach I use but you are free to approach this any way you like
4
+
// This file walks you through the approach I use but you are free to do this any way you like
5
5
6
6
// Enqueue front-end scripts and styles
7
7
functionvoidx_enqueue_scripts() {
8
8
9
-
$script_name = ''; // Empty by default, may be populated by conditionals below
9
+
$script_name = ''; // Empty by default, may be populated by conditionals below; this is used to generate the script filename
10
10
$script_vars = array(); // An empty array that can be filled with variables to send to front-end scripts
11
-
$script_handle = 'voidx'; // A generic script handle
12
-
$suffix = '.min'; // The suffix for minified scripts
13
-
$ns = 'wp'; // Namespace for scripts
14
-
15
-
// Load original scripts when debug mode is on; this allows for easier local development
16
-
if ( WP_DEBUG === true )
17
-
$suffix = '';
11
+
$script_handle = 'voidx'; // A generic script handle used internally by WordPress
12
+
$ns = 'wp'; // Namespace for scripts; this should match what is specified in your `gulpconfig.js` (and it's safe to leave alone)
18
13
19
14
// Figure out which script bundle to load based on various options set in `src/functions-config-defaults.php`
20
-
// Note: bundles require less HTTP requests at the expense of addition caching hits when different scripts are requested
21
-
// You could also load one main bundle on every page with supplementary scripts as needed (e.g. for commenting or a contact page)
15
+
// Note: bundles require fewer HTTP requests at the expense of addition caching hits when different scripts are requested on different pages of your site
16
+
// You could also load one main bundle on every page with supplementary scripts as needed (e.g. for commenting or a contact page); it's up to you!
17
+
18
+
19
+
20
+
// == EXAMPLE INTEGRATION == //
22
21
23
22
// An example integration using WP AJAX Page Loader; this script requires a bit more setup as outlined in the documentation: https://github.com/synapticism/wp-ajax-page-loader
24
23
$script_vars_page_loader = '';
25
24
26
25
// This conditional establishes whether the page loader bundle is loaded or not; you can turn this off completely from the theme configuration file if you wish (or just remove the code)
$script_name .= '-pageloader'; // This is used to generate the filename that the theme will serve to the user; it is additive to allow for multiple features that can be toggled in the theme configuration
29
27
30
-
global$wp_query;
28
+
// The script name is used to specify the file that the theme will serve to users
29
+
// Script names are designed to be additive (meaning you can append more script names to the end in other conditional blocks using `.= '-anotherscript'` etc.) to allow for multiple feature toggles in the theme configuration
30
+
$script_name .= '-pageloader';
31
31
32
-
// This chunk of code provisions the script with some important information it needs: What page are we on? And what is the page limit?
32
+
// This chunk of code provisions the WP AJAX Page Loader script with some important information it needs: What page are we on? And what is the page limit?
// Prepare script variables; note that these are separate from the rest of the script variables as this script requires everything in an object named `PG8Data`
37
+
// Prepare script variables; note that these are separate from the rest of the script variables as the WP AJAX Page Loader script requires everything in a specific object named `PG8Data`
37
38
$script_vars_page_loader = array(
38
39
'startPage' => $paged,
39
40
'maxPages' => $max,
40
41
'nextLink' => next_posts( $max, false )
41
42
);
42
43
} // WP AJAX Page Loader configuration ends
43
44
44
-
// Default script name
45
+
46
+
47
+
// Default script name; used when conditional blocks (above) aren't triggered
45
48
if ( empty( $script_name ) )
46
49
$script_name = '-core';
47
50
48
51
// Load theme-specific JavaScript bundles with versioning based on last modified time; http://www.ericmmartin.com/5-tips-for-using-jquery-with-wordpress/
49
52
// The handle is the same for each bundle since we're only loading one script; if you load others be sure to provide a new handle
// Script variables for WP AJAX Page Loader (these are separate from the main theme script variables due to the naming requirement; the object must be `PG8Data`)
60
+
// Script variables specific to WP AJAX Page Loader (these are separate from the main theme script variables due to the naming requirement; the object must be `PG8Data`)
61
+
// This appears and NOT in the conditional block (above) because these variables will be attached to the main script handle (which may be modified after the page loader block)
// Non-destructively merge script variables if a particular condition is met (e.g. `is_archive()` or whatever)
77
+
// Non-destructively merge script variables if a particular condition is met (e.g. `is_archive()` or whatever); useful for managing many different kinds of script variables
0 commit comments