WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On the home page I a have 2 lines of code I would like to run in JavaScript.

Where should I put these two lines of code.

Does WP have a specific way to do this. Or should I just pick the last .js file that loads and add it there?

share|improve this question
Depends on what the javascript is. What is it? Add the js code to your question. – markratledge Oct 2 '12 at 23:37
it's simply to remove an element. – user14432 Oct 3 '12 at 0:21
up vote 0 down vote accepted

yes, WordPress has a function for loading javascript files: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

the last argument takes either true or false to load in the footer

share|improve this answer
thanks for the link..the codex is a beast. – user14432 Oct 3 '12 at 0:22

Depends on what the javascript is. What is it? Add the js code to your question.

If it's an externally loaded script that does nothing more than track page loads - like google analytics or other stat counter code - there's no reason to use wp_enqueue_script. Sometimes you can simply add it to footer.php or header.php

If you need the js to run specifically when the page is finished loading, then you need to wrap it in a jQuery function called .ready()

jQuery(document).ready(function($) {
  // Code using $ as usual goes here.

See http://api.jquery.com/ready/

And if the code is jQuery, you may need to wrap it in a noConflict wrapper to prevent conflicts with other js.

<script type="text/javascript">
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  // Code that uses other library's $ can follow here.
share|improve this answer
that's what i ended up doing....adding it to the footer. – user14432 Oct 3 '12 at 0:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.