Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created this theme and it worked on my site without any problem. When I moved it to another server, I get wp_register_script was called incorrectly. error.

I scanned my source code and I didn't use any wp_register_script ... however I am suspecting that it is reacting to this ...

function add_script_code() {
    wp_deregister_script('jquery'); 
    wp_enqueue_script('jquery', base_url('source/js/jquery-1.4.1-vsdoc.js'), false, '1.3.0', TRUE );
    wp_enqueue_script('less', base_url('source/js/less-1.3.0.min.js'), false, '1.3.0', TRUE );
    wp_enqueue_script('vars', base_url('source/js/vars.js'), false, '1.3.0', TRUE);
    wp_enqueue_script('function', base_url('source/js/function.js'), false, '1.3.0', TRUE );
}

//add_action('admin_init', 'add_script_code');
add_action('wp_footer', 'add_script_code')

My code base is in github. The functions folder contains my functions for the theme.

https://github.com/abarcenas29/dmp-v4

Base url is a function I created.

function base_url($url) {
        return get_bloginfo('template_url').'/'.$url;
    }
share|improve this question
1  
Particularly, I've never seen this base_url used before... –  brasofilo Jan 9 '13 at 11:50
    
Sorry about that. I added the fucntion for it. It is also on the default_func.php file. @brasofilo –  Mr A Jan 9 '13 at 12:41
    
I believe that wp_enqueue_script() code should be attached to an early hook, like wp_head or wp_enqueue_scripts, and the fifth argument will load the script in footer –  bungeshea Jan 9 '13 at 12:46
    
Why did my theme work on my other server then? This error only happened when I move it in another wp install. @bungeshea Also, could you cite and example? –  Mr A Jan 9 '13 at 12:48
    
I don't know why you are receiving different server responses, but see my answer below for guidance on how to fix your issue –  bungeshea Jan 9 '13 at 12:58

3 Answers 3

You need to hook your function into either wp_enqueue_scripts, admin_enqueue_scripts, or init. wp_footer is too late to enqueue scripts; they need to be enqueued before the wp_head() function is called.

The fifth argument of the wp_enqueue_scripts() function, when set to true, will load the script in the page footer instead of header. From the Codex:

You have to enqueue your script before wp_head is run, even if it will be placed in the footer

share|improve this answer
    
I tried editing ... add_action('wp_footer', 'add_script_code') to add_action('init', 'add_script_code') but still gave me the same error. –  Mr A Jan 9 '13 at 13:36

Are the WordPress versions the same on both servers? I believe the notice was added in version 3.3. Also, bungeshea is right about enqueueing your script before wp_head is run - meaning you should be hooking into either init or wp_enqueue_scripts hook.

oh yeah, the 3rd argument should be an array not boolean so the call should look like this:

wp_enqueue_script('function', base_url('source/js/function.js'), array(), '1.3.0', TRUE );
share|improve this answer
    
You should actually use false for the third argument if your script has no dependencies. See the Codex for details –  bungeshea Jan 9 '13 at 21:18
    
@bungeshea: the Codex does not use false ;) The parameter type clearly says it should be an array. In fact, the default value for the 3rd paramter is an empty array() which is used when there are no dependencies. –  WP Themes Jan 17 '13 at 15:22
    
Read again: Array of handles of any script that this script depends on (scripts that must be loaded before this script). false if there are no dependencies –  bungeshea Jan 17 '13 at 22:49

I found the culprit. My theme was written in short tags. My server short tags was off. So I just converted my theme to use <?php and everything worked.

Thanks for helping me.

share|improve this answer
    
Please accept your answer using the tick to the left of your answer –  bungeshea Jan 9 '13 at 21:19

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.