I’m still quite new to wordpress, and having built and developed my first theme (that all works fine). My second attempt at a CMS site on wordpress I am having some trouble with. That trouble being the jQuery.
The site all works (bar the jQuery) which is the frustrating part, after reading up about how to correctly call jQuery in wordpress, I read that the proper way to do it is via enqueue the script in the functions file.
Taking the code from my functions.php from my first site and using it on this one
<?php
function fff_script_method() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', '/themes/wahoo/js/jquery.min.js');
wp_enqueue_script( 'jquery' );
}
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
add_action('wp_enqueue_scripts', 'fff_script_method');
?>
But it doesn’t seem to work this time round, and I also need to call various scripts, last time round I called this script via functions.php and the rest in my header.php file using the regular method
<script type="text/javascript" src="/wp-content/themes/wahoo/js/jquery.imagesloaded.js"></script>
But again this doesn’t seem to be working this time round, and any changes I make in the function.php file just result in a syntax error which then means I have to replace the file on the FTP again.
It’s incredibly frustrating and I can’t seem to figure out why the jQuery is loading this time round, I have also gone to the effort of making sure my jQuery files aren’t conflicting and using ‘jQuery’ instead of ‘$’.
Any advice would be greatly appreciated, and how do you correctly register and enqueue more than one script so I can see if that works too?
Rather than de- and re-registering jQuery (which shouldn’t be necessary if you’re avoiding conflicts), try this:
The function calls wp_register_script with three arguments: 1) a string to name the script, 2) the path of the script using
get_template_directory_uri()to make sure you aren’t messing up the paths, and 3) any dependancies – jQuery in this case.