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'm currently creating a plugin that requires me to overwrite one of the Wordpress admin panel javascript files. I have recreated the file with the changes, I need to know how to replace the existing file that gets loaded in load_scripts.php (the script needs to be added in the same order).

I was hoping something like this would do the job:

wp_register_script('admin-widgets', WP_PLUGIN_URL. '/oak-automated-sidebars/oak-widgets.js'); wp_enqueue_script('admin-widgets');

But it doesn't seem to work, the original script is still loaded. Any suggestions?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You need to first deregister the script using wp_deregister_script

 wp_deregister_script( 'admin-widgets' );

then use your code to re-register the script using your own js file:

wp_register_script('admin-widgets', WP_PLUGIN_URL. '/oak-automated-sidebars/oak-widgets.js'); 
wp_enqueue_script('admin-widgets');

Hope this Helps

share|improve this answer
    
I've tried that as well, it no longer includes the old code, but it includes the new code seperately and not through load_scripts.php. It's throwing errors as a result of being loading in the wrong order, is there anyway to get it to include it in the same place through load_scripts.php? –  Dave Hunt Feb 8 '11 at 0:36
    
i'm guessing removing all of the script on load_scripts.php and enqueue them back in the right order. –  Bainternet Feb 8 '11 at 0:41
    
It's not adding my script to load_scripts.php at all, its calling it as a separate javascript file. –  Dave Hunt Feb 8 '11 at 0:43
2  
that is because the use of wp_register_script with a url to the js file it suppose to load it separately and that is why if you need to keep order dependency you can use it in the $dep array in wp_enqueue_script( $handle, $src, $deps); and define your dependencies. –  Bainternet Feb 8 '11 at 0:52
    
That was exactly the problem, everything working as it should now, much appreciated! –  Dave Hunt Feb 8 '11 at 1:24

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.