Skip to content

Instantly share code, notes, and snippets.

@kellymears
Created August 21, 2012 17:18
Show Gist options
  • Save kellymears/3417483 to your computer and use it in GitHub Desktop.
Save kellymears/3417483 to your computer and use it in GitHub Desktop.
registering & deregistering jquery scripts on as-needed basis
<?php // this is an excerpt from functions.php ?>
<?php
function register_ueg_scripts($version='development') {
$template = get_template_directory_uri();
// jquery
wp_register_script('jquery','/js/jquery.1.7.1.min.js');
wp_enqueue_script('jquery');
// superfish
$superfish = $template .'/js/superfish.js';
wp_register_script('superfish',$superfish);
wp_enqueue_script('superfish');
// hoverintent
$hoverintent = $template .'/js/hoverIntent.js';
wp_register_script('hoverintent',$hoverintent);
wp_enqueue_script('hoverintent');
// bootstrap
$bootstrap = $template .'/bootstrap/js/bootstrap.js';
wp_register_script('bootstrap',$bootstrap);
wp_enqueue_script('bootstrap');
// jquery.color
$jquery_color = $template .'/js/color/jquery.color.js';
wp_register_script('jquery_color',$jquery_color);
wp_enqueue_script('jquery_color');
// bitly
$bitly = $template .'/js/bitly/jquery.bitly.js'
wp_register_script('bitly',$bitly);
wp_enqueue_script('bitly');
// proquo
$proquo = $template .'/js/proquo/jquery.proquo.js';
wp_register_script('proquo',$proquo);
wp_enqueue_script('proquo');
// development scripts
if($version=='development') {
// less
$less = $template .'/less/less.js';
wp_register_script('less',$less);
wp_enqueue_script('less');
// modernizr
$modernizr = $template .'/js/modernizr/modernizr.js';
wp_register_script('modernizr',$modernizr);
wp_enqueue_script('modernizr');
}
// production scripts
if($version=='production') {
// modernizr
// modernizr_prod
// modernizr_prod
}
}
function deregister_ueg_scripts() {
if (!is_page(array('code','whos-at-risk'))) {
wp_deregister_script('wp_mm_script');
wp_deregister_script('wp_wax_script');
wp_deregister_style('wp_wax_style');
}
if (!is_page('home')) {
wp_deregister_script('jquery.anythingslider');
wp_deregister_script('swfobject');
wp_deregister_script('jquery.anythingslider.video');
wp_deregister_script('jquery.easing');
wp_deregister_script('jquery.anythingslider.fx');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment