Register a script to be enqueued both in admin and front end

You can register the scripts earlier, for example on wp_loaded:

add_action( 'wp_loaded', 'register_all_scripts' );

function register_all_scripts() 
{
    wp_register_script(...);
}

And then you enqueue the scripts whenever you need them:

add_action( 'wp_enqueue_scripts', 'enqueue_front_scripts' );
add_action( 'admin_enqueue_scripts', 'enqueue_back_scripts' );

Use the same handles and names to avoid collisions with other scripts.

Leave a Comment