forgive me but I am an amateur so I have limited knowledge.
I want to know the best way to add jQuery to my custom WordPress theme. Previously I just used the following code:
I have learnt that apparently this is not the best practice way and that the best practice way is to use the wp_enqueue_script function to add jQuery. Therefore I created an index.php and functions.js file which I have copied down below.
<p class=”enqTest”>This font should be blue</p>
My aim here is to use jQuery to change the font color of the text however I am trying to use wp_enqueue_script to load jQuery. It does not work. What am I missing here?
I have looked at other questions, interestingly another user said jQuery can only be loaded when it has been marked as a dependancy for a different script. Is this true? Would I then need to take the jQuery function out of my index.php file, add it to a new script file and register then enqueue that script file in the adding_jquery function in my functions.php file?
Read more here:: Difficulty loading jQuery with wp_enqueue_script