When should I use wp_register_script() with wp_enqueue_script() vs just wp_enqueue_script()?


I’m having trouble understanding when you need to use wp_register_script(). Currently, I just use something like:

add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
function enqueue() {
    $handle = 'some-handle';
    $js = 'http://example.com/my.js';
    wp_register_script( $handle, $js );
    wp_enqueue_script( $handle );

I’ve done a lot of reading (Codex, blogs, etc.), but can’t quite understand when I should register first, or when I should just enqueue. As an example, I noticed TwentyTwelve doesn’t register any styles or scripts, it just enqueues them.

, akTed 10 years 2013-01-21T08:36:50-05:00 0 Answers 93 views 0

Leave an answer