Enqueue Javascript


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Code in functions.php:
  2.  
  3. function my_theme_scripts() {
  4.  
  5. if ( !is_admin() ) { // instruction to only load if it is not the admin area
  6. // register your script location, dependencies and version
  7. wp_deregister_script( 'jquery' );
  8. wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js');
  9. wp_enqueue_script( 'jquery' );
  10.  
  11. wp_register_script('custom_script',
  12. get_bloginfo('stylesheet_directory') . '/js/expand_collapse.js',
  13. array('jquery'),
  14. '1.0' );
  15. // enqueue the script
  16. wp_enqueue_script('custom_script');
  17. }
  18. }
  19.  
  20. add_action('init', 'my_theme_scripts');
  21.  
  22. // /js/expand_collapse.js in child theme:
  23.  
  24. <script type="text/javascript">
  25. jQuery(document).ready(function($) {
  26. $('#upNav').hide();
  27.  
  28. $('#showBtn').click(function() {
  29. $('#upNav').toggle();
  30. });
  31.  
  32. $('#parent').hover(function() {
  33. $('#upNav').show();
  34. });
  35.  
  36. $('#parentNav').mouseleave(function() {
  37. $('#upNav').hide();
  38. });
  39. });
  40. </script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.