Posted By

ihatetomatoes on 02/26/13


Tagged

wodrpress


Versions (?)

WP - Load script only on some pages


 / Published in: PHP
 

URL: http://www.position-relative.com/2010/wordpress/wordpress-only-load-plugins-on-pages-that-need-them/

Load scripts only on pages which needs them.

  1. /**
  2.  * Additional JS - Scrollorama and header animation only on homepage
  3.  *
  4.  * @since 1.0.0
  5.  *
  6.  */
  7. function scripts() {
  8. wp_enqueue_script( 'jquery' );
  9.  
  10. wp_register_script( 'enquire', get_stylesheet_directory_uri().'/assets/js/enquire.min.js');
  11. wp_enqueue_script( 'enquire' );
  12. wp_register_script( 'greensock', get_stylesheet_directory_uri().'/assets/js/libs/greensock/TweenMax.min.js');
  13. wp_enqueue_script( 'greensock' );
  14. wp_register_script( 'scrollorama', get_stylesheet_directory_uri().'/assets/js/jquery.superscrollorama.js');
  15. wp_enqueue_script( 'scrollorama' );
  16. wp_register_script( 'headerAnimation', get_stylesheet_directory_uri().'/assets/js/_header-animation.js');
  17. wp_enqueue_script( 'headerAnimation' );
  18.  
  19. if ( !is_front_page() ) {
  20. wp_deregister_script('scrollorama');
  21. wp_deregister_script('headerAnimation');
  22. }
  23. }
  24. wp_enqueue_script( 'base' );
  25.  
  26. add_action( 'wp_print_scripts', 'scripts'); // now just run the function

Report this snippet  

You need to login to post a comment.