Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created January 10, 2013 17:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wpsmith/4504030 to your computer and use it in GitHub Desktop.
Save wpsmith/4504030 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' );
}
@devloprs
Copy link

devloprs commented Jul 2, 2017

This has literally saved my bacon. I was trying to get this script to load for over a week! Your solution is five years old and still relevant .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment