javascript - How do I put jQuery code in an external file in WordPress theme? -


i relatively new javascript/jquery please bear me.

i'm designing custom wordpress theme , have been using jquery make changes main navigation menu generated in header file (header.php). have been adding code inside head tag:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>   <script>     $(document).ready(function(){       $('nav').mouseover(function() {         // mousecode here...       }); // end mouseover     }); // end ready   </script> 

my question simple really. scripts have gotten long want move them own file (perhaps nav-mouse-events.js) , call them within header.php. how do this? simple putting code inbetween second script tags file named nav-mouse-events.js , adding head tag?

<script src="nav-mouse-events.js"></script> 

or need more complicated? need call jquery new external file or header.php?

you put scripts in .js file , use wp_enqueue_script in functions.php include them proper way.

from wordpress site:

<?php function my_scripts_method() {     wp_enqueue_script(         'custom-script',         get_template_directory_uri() . '/js/custom_script.js',         array( 'jquery' )     ); }  add_action( 'wp_enqueue_scripts', 'my_scripts_method' ); ?> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -