dimanche 15 février 2015

JavaScript in WordPress not loading


So I'm trying to get a custom JavaScript file working on my pages that alters element heights on my pages (saves me having to do it as it's different on each page) though it doesn't work.


I've tried adding it through PHP and HTML in the header.php, functions.php, footer.php and even in the actual page itself.


If will load for the very first time, not work, and then when I go set break points and refresh, it doesn't load.


I have the file in the theme's JavaScript folder and the methods I've used to add it are:



<script src="<?php echo get_template_directory_uri(); ?>/js/elementHeight.js"></script> (header and footer)

wp_enqueue_script( 'elementHeight', get_template_directory_uri().'/js/elementHeight.js', array( 'jquery' ), '1' ); (functions)


I don't know what's going on. The first time I loaded it in the page, I noticed it actually fetched everything in the file and pasted it within the two <script> tags minified but also in CDATA tags.


Is there a reason my script isn't loading and/or is there something I'm missing?


EDIT: I just noticed that the script gets added to the page but the link has .pagespeed.jm.d-4Yn-ag4z.js appended to it which is an old cached version though I don't have any caching plugins. Can someone tell me what's going on?





Aucun commentaire:

Enregistrer un commentaire