Skip to content

Instantly share code, notes, and snippets.

@itsjusteileen
Forked from wpsmith/wps_load_scripts.php
Created September 2, 2019 17:57
Show Gist options
  • Save itsjusteileen/83a64e7be4b6644de6af5e49bff85a39 to your computer and use it in GitHub Desktop.
Save itsjusteileen/83a64e7be4b6644de6af5e49bff85a39 to your computer and use it in GitHub Desktop.
Enqueue Isotope
<?php
add_action( 'wp_enqueue_scripts', 'wps_load_scripts' );
/**
* Enqueue Isotope
* For commercially developed child themes, you must obtain a license
* from isotope.metafizzy.co for approx. $25.
*
* @author Travis Smith
* @link http://wpsmith.net
* @link http://isotope.metafizzy.co
* @link https://github.com/desandro/isotope
* @link http://codex.wordpress.org/Function_Reference/wp_enqueue_script
* @link http://codex.wordpress.org/Function_Reference/wp_register_script
* @link http://codex.wordpress.org/Function_Reference/get_post_meta
*
* @uses wps_enqueue_jquery() Registers and enqueues Google CDN jQuery or WordPress jQuery.
* @uses wp_register_script() Registers javascripts for use with wp_enqueue_script() later.
* @uses wp_enqueue_script() Enqueues javascript.
* @uses get_post_meta() Gets post meta for a specific post.
*/
function wps_load_scripts() {
// Setup suffix according to WordPress Coding Standards and jQuery Conventions
// Load dev version if in debug mode
// Must have dev versions and minified versions in js folder
$suffix = ( WP_DEBUG || WP_SCRIPT_DEBUG ) ? '.js' : '.min.js';
// Enqueue jQuery, always
// See https://gist.github.com/4083811
// Feel free to remove this line below, and everything will still work fine!
wps_enqueue_jquery(); // optional
// Register Isotope, so it can be called anytime
// Prefix everything!
wp_register_script( 'wps-isotope', get_stylesheet_uri() . '/js/jquery.isotope' . $suffix, array( 'jquery' ), '1.5.21', true );
// Register Isotope Parameters, so it can be called anytime
// Create minified isotope-parameters version at http://jscompress.com
// isotope-parameters file named: isotope-parameters.min.js
wp_register_script( 'wps-isotope-parameters', get_stylesheet_uri() . '/js/isotope-parameters' . $suffix, array( 'wps-isotope' ), '1.5.21', true );
// Enqueue Isotope Scripts only when needed (home, page template, custom field set)
global $post; // Remove if not using get_post_meta()
if ( is_home() || is_page_template( 'my-super-cool-template.php' ) || get_post_meta( $post->ID, 'wps_isotope' ) )
wp_enqueue_script( 'wps-isotope-parameters' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment