Awesome! Thanks.
I also thought it would be nice to:
- Have a new constant to specify whether to load the inline_script in the wp_head or wp_footer (in my opinion it should defaults to footer).
- Eventually “improve” the way you inlined the main script (See below)
I was thinking of something like this, which I believe is a bit cleaner:
function inline_scripts() {
if ( wp_script_is( 'jquery', 'done' ) ) {
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
if (jQuery().colorbox) {
// MAIN SCRIPT GOES HERE:
// 1) It will only be loaded if jQuery is loaded
// 2) It will only be executed if Colorbox is loaded
}
});
</script>
<?php
}
}
add_action( 'wp_footer', 'inline_scripts' );
Lemme know what you think.