acf-composer
acf-composer copied to clipboard
Equeue script depending on ACF field
Hello! Is there a way to decide inside of enqueue() method eather to enqueue 3rd party script or not depending on the value of ACF true/false field in block? We have a custom form block, so if the field is set to TRUE we want the js script to be enqueued in enqueue() method. Here is example what's needed but doesn't work because get_field returns null in enqueue():
public function enqueue(): void
{
$chilipiper = (bool) get_field('chilipiper');
if (true === $chilipiper) {
wp_enqueue_script('chilipiper-lib');
bundle('chilipiper')->enqueue();
}
}
Thanks in advance!
Hello! Is there a way to decide inside of enqueue() method eather to enqueue 3rd party script or not depending on the value of ACF true/false field in block? We have a custom form block, so if the field is set to TRUE we want the js script to be enqueued in enqueue() method. Here is example what's needed but doesn't work because get_field returns null in enqueue():
public function enqueue(): void { $chilipiper = (bool) get_field('chilipiper'); if (true === $chilipiper) { wp_enqueue_script('chilipiper-lib'); bundle('chilipiper')->enqueue(); } }Thanks in advance!
If you find a way to get the values from a get_field, please let me know. I am encountering the same issue.
https://github.com/Log1x/acf-composer/issues/143
The commit that codepuncher has put in does in fact work to allow me to fetch block data.