# Registering AND enqueueing scripts and styles

While the post title might seem humorous it’s the first time, in a short time span really, I find myself thanking WordPress for giving me a function like wp_register_script.
While the use of such a function and its field of operations is not difficult to understand the specific situation it’s solving for me is the one where I’ve added scripts in my library set and would like to use those later in themes and plugins; while I can easily write something like

wp_enqueue_script( 'jquery-address', TADLIBS_ASSETS_URL . '/assets/js/vendor/jQuery/jquery.address.js', array('jquery'));

in said themes and plugins the solution is patchy as it implies deep knowledge of the file organization and the single script dependencies. In the library set plugin main file I register the scripts like

// Register the scripts for later use

$srcRoot = TADLIBS_ASSETS_URL . '/assets/js'; wp_register_script( 'jquery-address',$srcRoot . '/vendor/jQuery/jquery.address.js', array('jquery'), NULL);

wp_register_script( 'jquery-urlInternal', $srcRoot . '/vendor/jQuery/jquery.urlInternal.min.js', array('jquery'), NULL); wp_register_script( 'jquery-ajaxify',$srcRoot . '/src/jquery.ajaxify.js', array('jquery', 'jquery-address', 'jquery-urlInternal'), NULL);

and then, in themes and plugins, will simply queue them

wp_enqueue_script( 'jquery-ajaxify');

decoupling the code from the library set file structure, organization and dependency web.