Skip to content

Instantly share code, notes, and snippets.

@maxkandler
Created January 26, 2012 07:42
Show Gist options
  • Save maxkandler/1681564 to your computer and use it in GitHub Desktop.
Save maxkandler/1681564 to your computer and use it in GitHub Desktop.
Wordpress – Cleaning up the JavaScripts: - load jQuery at the end of the page - load own JavaScript - embed JS for Contact Form 7 only when needed.
<?php
/**
* Cleaning up the scripts
*/
function jc3_register_scripts() {
// Put jQuery to the bottom
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', false, '1.7.1', true );
wp_enqueue_script( 'jquery' );
wp_register_script( 'jc3' , get_template_directory_uri() . '/jc3.js', false, '1.0', true);
wp_enqueue_script( 'jc3' );
// Include the Contactform7 JS-file only when used.
global $post;
if($post->post_name != "kontakt"){
wp_deregister_script( 'contact-form-7' );
}
}
add_action('wp_enqueue_scripts', 'jc3_register_scripts');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment