I have an enqueued script called custom_js
that loads the file js/custom.js
. I want the file to change when a certain condition is true, but it does not seem to work. Here is my code:
add_action('wp_print_scripts', 'my_custom_js', 11);
function my_custom_js()
{
wp_enqueue_script( 'custom_js', get_template_directory_uri().'/js/custom.js' );
if ( some condition )
{
wp_enqueue_script( 'custom_js', get_template_directory_uri().'/js/custom-2.js');
}
}
Enqueuing another script seems unnecessary to me; what is the best way to manipulate a script that has been enqueued? Also, it is not very clear to me - do I have to register
custom enqueued scripts?