The following snippet to allow javascript with ACF needed to add in header.php before the </head> tag.
<?php the_field(‘header_script'); ?>
But I would like to add to functions.php instead of header.php.
How can I add the snippet to the functions.php?
This should do the trick. Simply add it to your functions document. the \n is a line break to make your code look nicer when it spits it out.
add_action('wp_enqueue_scripts', 'customJsFunction');
function customJsFunction(){
global $post;
$script= get_field('header_script',$post->ID);
if($script){
echo '<script>'."\n".$script."\n".'</script>'."\n";
}
}