Title: adding custom javascript to a theme
Last modified: August 21, 2016

---

# adding custom javascript to a theme

 *  [jfarr13](https://wordpress.org/support/users/jfarr13/)
 * (@jfarr13)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/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.

Viewing 1 replies (of 1 total)

 *  Thread Starter [jfarr13](https://wordpress.org/support/users/jfarr13/)
 * (@jfarr13)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-javascript-to-a-theme/#post-4480529)
 * Answered my own question, I just piggybacked a current theme script and added
   it to that 🙂

Viewing 1 replies (of 1 total)

The topic ‘adding custom javascript to a theme’ is closed to new replies.

## Tags

 * [adding](https://wordpress.org/support/topic-tag/adding/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [problem](https://wordpress.org/support/topic-tag/problem/)

 * 1 reply
 * 1 participant
 * Last reply from: [jfarr13](https://wordpress.org/support/users/jfarr13/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-javascript-to-a-theme/#post-4480529)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
