Adding jQuery to WordPress theme

Hi, I am trying to add this script to Zerif theme so i can have a multi-layered parralax background:

So far i have added the two JS files to a folder called “pjs” in my theme folder and inserted the

<script src=”http://code.jquery.com/jquery-1.11.3.min.js”></script>

<script src=”jquery.enllax.min.js”></script>

and the activation script and the divs containing the image layers
below that, but i am unsure what to do next. I guess I need to enqueue
the script somehow. I have tried multiple tactics but nothing is
working.

Can anyone point me in the right direction??

Have a look at the html partials in the theme directory, Ideally you want to add new scripts right before the closing </body> tag.

<script src="path-to-scripts.js"></script>

Hi @agxer, jQuery comes installed and registered in WP by default, so you only need to enqueue it like

wp_enqueue_script('jquery');

in your functions.php. Scripts that depend on jQ can then be registered like

wp_register_script('my-script', get_template_directory_uri() . '/pjs/my-script.js', ['jquery']);

and enqueued when needed like

wp_enqueue_script('my-script');

Don’t hard-link scripts in <script> tags – let WP handle this for you. This makes the site easier to maintain and migrate (especially when you want to set up a local dev environment) and your theme more reusable.

BTW, it looks like you tried to include some code snippets in your post… you have to escape HTML tags with backticks to make them show, like

`<div>foo</div>`

or if you have a block of code, just select it and click the </> button. Also makes it nicer to read. :-)

I’ve fixed that up now so the script tags are visible in the original post

1 Like

Ah thx, just what I thought then. ^^

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.