wp_register_script was called incorrectly


February 01, 2012 at 10:27
Wordpress

If you set debug to true in wordpress, you might get a notice that wp_register_script or wp_enqueue_script was called incorrectly. The solution to this is to not call these functions directly but wrap them in an action: Before:
if ( !is_admin() ) {
    wp_deregister_script('jquery');
    wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"), array('jquery'));
    wp_enqueue_script('jquery');
}
After:
if ( !is_admin() ) {
    add_action('wp_enqueue_scripts', 'enqueue_scripts');    
}    

function enqueue_scripts() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"), array('jquery'));
    wp_enqueue_script('jquery');
}
And the notice is gone!

Tags: debug fehlerhaft incorrectly notice wordpress


Hinterlasse einen Kommentar:
Search