Skip to content

Instantly share code, notes, and snippets.

@alwerner
Last active December 16, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alwerner/5438300 to your computer and use it in GitHub Desktop.
Save alwerner/5438300 to your computer and use it in GitHub Desktop.
Wordpress conditional script loading in functions.php. Source: http://www.organizedthemes.com/loading-scripts-conditionally/
if( !is_admin()){
wp_register_script('thescript', get_template_directory_uri() . '/path/to/thescript.js', array('jquery'), '1.2.3', true );
}
function conditional_scripts() {
if( !is_admin() && is_page('somepage') ){
wp_enqueue_script('thescript');
}
}
add_action('wp_enqueue_scripts', 'conditional_scripts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment