Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to get my custom javascript (jQuery) to load correctly in Wordpress. I know you have to use wp_enqueue_script() to do this correctly. However the problem I have is that the result is not my script, but in the place I should have javascript I have the code for a 404 page ! I've tried two ways of enqueueing the script :

wp_enqueue_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'),1);

just above wp_head() and :function my_script_load() { wp_enqueue_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'),null); } add_action('init', 'my_script_load');

in functions.php

both methods have the same effect. When I inspect the HTML in firebug I find the script is corredtly referenced :

<script src="http://localhost/wordpress/wp-content/themes/doric2011/javascript/sitescript.js" type="text/javascript">

however when I inspect the script itself I find the following (an extract) :` Page not found | Nick Kai Nielsen

and so on... It is a HTML output for a 404 page, but occupying a space where javascript should be... Needless to say the script does not work.

I have only had this problem since updating to 3.1 and it does the same thing if I try loading highslide.js and highslide.config.js (professionally written scripts). The script I wish to load is already working on my site and I want to go on using it in the new theme I am developing.

has anyone any idea of what is happening ? And, of course, what should I do about it ?

This is a local installation - I'm not risking breaking my site until this is sorted out.

share|improve this question
add comment

2 Answers

Try:

add_action('init', 'my_script_load');
function my_script_load() {
wp_register_script('sitescript', get_bloginfo('template_directory').'/javascript/sitescript.js', array('jquery'), true);
wp_enqueue_script('sitescript');
     } 
share|improve this answer
add comment

Assuming your javascript file is in the proper location (and the URL isn't pointing to a spot where the JS file isn't...) try this:

function add_my_scripts() {
   $templatedir = get_bloginfo('template_directory');
   if(!is_admin()) {
      wp_register_script( 'sitescript', $templatedir . '/javascript/sitescript.js');
      wp_enqueue_script( 'sitescript' );
   }
 }

 add_action( 'init', 'add_my_scripts');
share|improve this answer
    
I've god a red face and egg on it ! There was a typo in the address for the script... a whole day wasted ugh ! Only lesson - I know what a badly addressed script gives in firebug ! –  Nick May 4 '11 at 7:02
    
LOL - happens to the best of us! –  Shelly May 6 '11 at 15:10
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.