“ReferenceError: jQuery is not defined” after deployment
-
Hi,
I updated a js script in a custom theme (I am a beginner in WP, so I did not develop it). Everything works fine on the development environment, but I have a problem when I deployed it: WP did not “reload” and minimize neiher the modified js script nor the modified css stylesheet and is not able to use JQuery anymore.
After some research I found that the script and the css was directly inserted in header.php and footer.php (<script> and <link>) so I deleted these lines and re-implemented them with the wordpress “enqueue” functions in functions.php like this :
define('CSSVERSION', 1.0); define('SCRIPTVERSION', 1.0); function load_custom_assets() { wp_enqueue_style('main-style', get_template_directory_uri().'/css/main-style.css', false, CSSVERSION, 'all'); wp_enqueue_script( 'custom-front-script', get_template_directory_uri().'/js/custom-front-script.js', array('jquery'), SCRIPTVERSION, true ); } add_action('wp_enqueue_scripts', 'load_custom_assets');
It still works in development and now the css works in production (but not the script). There are errors in the console :
– First the page can’t use JQuery “ReferenceError: jQuery is not defined”
– There is a syntax error in a compiled/minimified file…
– my “custom-front-script.js” because the window don’t know my “toggleAnimation” and I’m not able to locate the <script> that WP must generate.. I guess it’s because the page can’t use JQuery, so JQuery is never loaded, so “enqueue” can’t generate the script tag ?I can give you the URL, but the changes are visible only for logged admin…
P.S :
In header.php I have a script that call jquery, is that ok or must I remove it and use enqueue ?
<script src="/acticontent/lib/jquery-3.1.1.min.js"></script>
- The topic ‘“ReferenceError: jQuery is not defined” after deployment’ is closed to new replies.