Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Enqueue Isotope
add_action( 'wp_enqueue_scripts', 'wps_load_scripts' );
* Enqueue Isotope
* For commercially developed child themes, you must obtain a license
* from for approx. $25.
* @author Travis Smith
* @link
* @link
* @link
* @link
* @link
* @link
* @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
// 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
// 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' );

This comment has been minimized.

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
You can’t perform that action at this time.