/ Published in: PHP

Load scripts only on pages which needs them.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Additional JS - Scrollorama and header animation only on homepage * * @since 1.0.0 * */ function scripts() { wp_enqueue_script( 'jquery' ); wp_register_script( 'enquire', get_stylesheet_directory_uri().'/assets/js/enquire.min.js'); wp_enqueue_script( 'enquire' ); wp_register_script( 'greensock', get_stylesheet_directory_uri().'/assets/js/libs/greensock/TweenMax.min.js'); wp_enqueue_script( 'greensock' ); wp_register_script( 'scrollorama', get_stylesheet_directory_uri().'/assets/js/jquery.superscrollorama.js'); wp_enqueue_script( 'scrollorama' ); wp_register_script( 'headerAnimation', get_stylesheet_directory_uri().'/assets/js/_header-animation.js'); wp_enqueue_script( 'headerAnimation' ); if ( !is_front_page() ) { wp_deregister_script('scrollorama'); wp_deregister_script('headerAnimation'); } } wp_enqueue_script( 'base' ); add_action( 'wp_print_scripts', 'scripts'); // now just run the function
URL: http://www.position-relative.com/2010/wordpress/wordpress-only-load-plugins-on-pages-that-need-them/
Comments
