Add script after all scripts in WordPress

Problem: Need add own script at the very end (after all scripts of the plugins) in WordPress and do it right and not just add tag <script> after wp_footer(),yeah, there are and such cases 🙂.

How to right add script at the very end (after all scripts) in WordPress

Solution: The problem arose because WordPress generally use many different plugins. In this case, order out of functions wp_enqueue_script() does not deliver desire result, because scripts of the plugins will be enabled after our enqueue. This problem can be solve as follows:

// Enqueue Custom Script In The End Of wp_footer()
add_action( 'wp_footer', 'enqueue_custom_script_in_wp_footer_end', 99 );

function enqueue_custom_script_in_wp_footer_end() {
    echo '<script src=' . get_template_directory_uri() . '/js/custom.js></script>'.PHP_EOL;
}

Leave Comment

Your email address will not be published.