Title: Adding javascript code to a specific wordpress page
Last modified: September 1, 2016

---

# Adding javascript code to a specific wordpress page

 *  [john.cressman](https://wordpress.org/support/users/johncressman/)
 * (@johncressman)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/)
 * I have a code snippet from a vendor that I need to add to one of the pages of
   my WordPress intranet site. The code snippet is similar to the below:
 *     ```
       <script src="http://support.ebsco.com/eit/scripts/ebscohostsearch.js" type="text/javascript"></script>
       <form><input name="db" type="hidden" value="" />
       <input title="Enter your search terms here to search DynaMed" maxlength="250" name="sb" size="30" type="text" value="Search DynaMed..." />
       <!-- [if IE]><input type="text" style="display: none;" disabled="disabled" size="1" /><![endif]-->
       <input title="Click Search to search DyanMed" name="submitType" type="submit" value="Search" /></form><strong>Get CE credits for searching DynaMed! <a href="DynaMed-for-CE-Credits.pdf" target="_blank">Click this link to learn more.</a></strong>
       ```
   
 * The search box shows up (that’s just straight html) but it doesn’t work and I
   think it’s because the javascript is not loading.

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [cedcommerce](https://wordpress.org/support/users/cedcommerce/)
 * (@cedcommerce)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-7555812)
 * Hello,
    You can easily enqueue your scripts file on specific page by checking
   the page like this
 *     ```
       function enqueue_files() {
         if ( is_page( 'your-page' ) ) {
           // enqueue specific page script files here
         } else {
           // enqueue common scripts here
         }
       }
       add_action( 'wp_enqueue_scripts', 'enqueue_files' );
       ```
   
 * .
 * Hope this will help you.
 * Thanks.
 *  Thread Starter [john.cressman](https://wordpress.org/support/users/johncressman/)
 * (@johncressman)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-7555813)
 * Thank you, but I’m looking for a more user-friendly option. We have 200+ departmental
   sites and if I need to program for each page of each site that might need some
   javascript, it’s going to be extremely burdensome.
 *  [Chris](https://wordpress.org/support/users/charlwood/)
 * (@charlwood)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-7555820)
 * You can also add it to the header.php theme template file …. you have 200 WordPress
   installs then? Not sure how you can avoid adding manually to each… [https://codex.wordpress.org/Using_Javascript](https://codex.wordpress.org/Using_Javascript)
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-7555821)
 * This will be something you should discuss with your hosting providers.
 *  [cedcommerce](https://wordpress.org/support/users/cedcommerce/)
 * (@cedcommerce)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-7555830)
 * As you asked here for enqueue scripts on specific page this is the way you can,
   also if you wants to add common script on all pages on front end you can simply
   use this code in your activated theme’s functions.php
 *     ```
       function enqueue_common_scripts() {
        wp_enqueue_script( 'my-scripts', get_stylesheet_directory_uri() . '/my-script.js', array( 'jquery' ), '1.0', true );
       }
   
       add_action( 'wp_enqueue_scripts', 'enqueue_common_scripts' );
       ```
   
 * but if you’re looking for other user-friendly option then please mark this as
   resolved, and generate a new thread mentioning about that issue.
 * Thanks.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-7555832)
 * There’s no need to generate a new thread for something that is outside the scope
   of the forums.
 *  Thread Starter [john.cressman](https://wordpress.org/support/users/johncressman/)
 * (@johncressman)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-7555862)
 * > you have 200 WordPress installs then? Not sure how you can avoid adding manually
   > to each…
 * Just to clarify… I am using WP Multisite, and yes, we have 200+ sites on our 
   intranet.
 * > This will be something you should discuss with your hosting providers.
 * We host our own WP on an IIS server, but I’m not sure what you mean by that. 
   How is hosting related to javascript not working?
 * > but if you’re looking for other user-friendly option then please mark this 
   > as resolved, and generate a new thread mentioning about that issue.
 * It’s not really resolved, so I’m not sure why I would mark it as resolved.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-7555903)
 * Initially you said:
 * > Adding javascript code to a specific wordpress page
 * But when people gave you advice for how to do just that, you said you didn’t 
   want to do it..
 * > We have 200+ departmental sites and if I need to program for each page of each
   > site that might need some javascript, it’s going to be extremely burdensome.
 * So, what you want is a service outside of your websites. An interface of some
   sort that will add JavaScript to all of your sites simultaneously. This is nothing
   to do with WordPress.
 *  [awtx](https://wordpress.org/support/users/awtx/)
 * (@awtx)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-8369931)
 * Did you check to make sure the web address is correct for the off-site javascript?
 * Oops, Andrew must have been out of coffee and a little grumpy. With a little 
   guidance the adding of javascript to all sites in a multisite installation does
   have to do with WordPress. Solving a non-WordPress javascript error for a third
   party form would indeed deserve that response.
 * I’m surprised someone didn’t remind him that he is using multi-site. Any change
   to the main “active” theme will affect every site using that theme. If each site
   uses a different theme, then he would be back to the same mass editing hassle.
   Most HTML editors have a search & replace function that will find all instances
   in files in directories so it really is just a 5-10 minute task.
 * He could also create a custom plugin with the enqueue code and place it in the
   plugins or mu_plugins (must use) directory. That would load it automatically 
   and instantly for all 200 sites in his multi-site installation. Unlike a standard
   plugin, this would only have the header and enqueue code.
    [https://codex.wordpress.org/Must_Use_Plugins](https://codex.wordpress.org/Must_Use_Plugins)
   [https://developer.wordpress.org/plugins/the-basics/header-requirements/](https://developer.wordpress.org/plugins/the-basics/header-requirements/)
 * It really is a good idea to only load the script on pages that use the form. 
   If the form is on every page, then the conditional should be changed to exclude
   admin pages.
 *     ```
       /wp-content/mu_plugins/enqueue-ebscoscript.php
   
       <?php
       /* 
       plugin header
       */
       function enqueue_ebscoform() {
         if ( is_page( 'ebsco-form-page-slug' ) ) {
            wp_register_script( 'ebscoform', '//support.ebsco.com/eit/scripts/ebscohostsearch.js', array( 'jquery' ), '1.0', true );
         } 
       }
       add_action( 'wp_enqueue_scripts', 'enqueue_ebscoform' );
       ?>
       ```
   
    -  This reply was modified 9 years, 6 months ago by [awtx](https://wordpress.org/support/users/awtx/).
      Reason: added mu_plugins directory reference
 *  [Matt Rock](https://wordpress.org/support/users/mattrock1/)
 * (@mattrock1)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-8814386)
 * Fantastic. Thanks for posting, cedcommerce!
 *  [synchro57](https://wordpress.org/support/users/synchro57/)
 * (@synchro57)
 * [9 years ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-9139810)
 * Hi,
 * Look at this plugin : [https://srd.wordpress.org/plugins/custom-css-js/](https://srd.wordpress.org/plugins/custom-css-js/)
 * It allows you to add JS/CSS/HTML on specific pages (premium version only). It’s
   user friendly and works well with WP multisite.
 * Good luck !

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Adding javascript code to a specific wordpress page’ is closed to new
replies.

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [must-use](https://wordpress.org/support/topic-tag/must-use/)
 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 7 participants
 * Last reply from: [synchro57](https://wordpress.org/support/users/synchro57/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/adding-javascript-code-to-a-specific-wordpress-page/#post-9139810)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
