I want to load all the scripts in $wp_scripts with my own JS function after the window.onload event. Is there a simple way to prevent wp_print_scripts from printing the default list of <script> tags so I can replace it with my own code?


There is a way, but it's not recommended since there might be some other inline scripts attached to the enqueued scripts. You can hook to the wp_enqueue_scripts action and empty the global $wp_scripts as follows:

add_action( 'wp_enqueue_scripts', 'remove_all_scripts', 1000 );
function remove_all_scripts() {
    global $wp_scripts;
    $wp_scripts->queue = array();

You can then run a loop and enqueue do whatever you want with them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.