You can still use the options in the old post you linked to. If you’re already using a custom or child theme, you can also edit functions.php
and add your custom JS wherever the main theme scripts are enqueued. For me personally it makes things simpler to add all theme CSS and JS in the same call, so if I ever wonder where something’s coming from, it is either in functions.php
or in a plugin somewhere.
add_action('wp_enqueue_scripts', 'wpse_305653_enqueues');
function wpse_305653_enqueues() {
// theme css
$version = filemtime(get_template_directory() . '/style.css');
wp_enqueue_style('wpse_305653', get_template_directory_uri() . '/style.css', array(), "$version", 'screen');
// theme scripts
wp_enqueue_script('wpse_305653-scripts', get_template_directory_uri() . '/scripts.min.js', array('jquery'), '2.3.4', true);
// only place this JS on the 'about' page
if(is_page('about')) {
wp_register_script('wpse_305653_conditional', get_template_directory_uri() . '/conditional.js', array('jquery'));
wp_enqueue_script('wpse_305653_conditional');
}
// only place this JS on singular 'program' CPTs
if(is_singular('program')) {
wp_register_script('wpse_305653_conditional2', get_template_directory_uri() . '/conditional2.js', array('jquery'));
wp_enqueue_script('wpse_305653_conditional2');
}
}
You may want to set up a CPT which becomes the only place the ACF fields appear on and therefore the only place the JS needs to enqueue. There are a number of other conditionals you can use here to single out the content you actually need the JS on.