0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

should I remove <script></script> tag?
0

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 );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.