adding custom javascript to a theme
-
Even though I am comfortable with javascript and implementing it, I am a bit lost with how to add my own script to my wordpress theme.
I have checked multiple results online and I tried everything.
Currently, I have uploaded my .js file in the /js folder (that holds all the other themes scripts), I also added this to the header.php file (all correct here)
<script type="text/javascript" src="/js/fade.js"></script>Then i added this in the functions.php file `function add_my_script() {
wp_enqueue_script(
‘fade’, // name your script so that you can attach other scripts and de-register, etc.
get_template_directory_uri() . ‘/js/fade.js’, // this is the location of your script file
array(‘jquery’) // this array lists the scripts upon which your script depends
);
}`bit no luck.
The script is a simple hover script which greys out every image other than the active hovered one. The class is assigned to the image and the css is added to the stylesheet. Locally it works fine but trying to get it working with WordPress is a bit of a nightmare. Is it that difficult to add my own script or am i missing something?
Any help greatly appreciated.
The topic ‘adding custom javascript to a theme’ is closed to new replies.