Reputation: 2869
I have jQuery and javascript code: XXXXXXXXXXXXXXXXXXXX
The code runs file in a Wordpress page if I put the code directly in the page: XXXXXXXXXXXXXXXXXXXXXXXXXXXX
But instead of putting code if I call the js file:
<script src="XXXXXXXXXXXXXXX"></script>
It doesn't work.
I have to put a common jquery and javascript code in many pages. So, I was thinking of putting all code in a js file and calling it from every page instead of copy-paste whole code in every page. How to do this?
Upvotes: 0
Views: 46
Reputation: 322
let's say you use the twentyfifteen theme: go to the /wp-content/themes/twentyfifteen/functions.php in the function twentyfifteen_scripts() add this line:
wp_enqueue_script( 'my-script', 'put here the URL of your js', array( 'jquery' ), '', true );
Upvotes: 0
Reputation: 25372
Your .js file includes opening and closing <script>
tags in it. This is valid in HTML, but not in JS. Your JS file is likely loading, but is failing on a syntax error because of those tags.
Upvotes: 1