I am going to redesign an existing site and will be using WordPress. The current site is on a different CMS. There are a lot of Javascript slideshow type files in the current site and it would take a long to time to recreate all the files.
Is it fairly easy to add the js files inside a template? Do you just add them like you normally would?
WordPress provides a better (recommended) way to add
scripts
using wp_enqueue_script function, for example, the following code (paste in yourfunctions.php
file) will add amy_custom_script.js
file fromyourThemeDirectory/js/
folderIn this given example, the first argument is the
handle/name
for your script, second parameter is the full path with file name that you want to add and the third parameter is the script dependency and in this case WordPress will require forjQuery
to be loaded before yourmy_custom_script.js
loads.To load the
jQuery
simply you can usewp_enqueue_script( 'jquery' )
withadd_action
, because inWordPress
some libraries are registered by default (including jQuery). Read the documentation for more details.