I am trying to enqueue a GSAP script only when a particular Gutenberg/Advanced custom field block is present on a page.
I used this for Slick slider and it works perfectly but for some reason it will not work with GSAP - I don't get any console errors (other than GSAP is not defined) and the script does not load.
I can't work out why? Any help would be appreciated
Thanks
This is Slick slider which works
acf_register_block_type(array(
'name' => 'lig_find_anything_carousel',
'title' => __('LIG Search Carousel'),
'description' => __('LIG Search Carousel'),
'render_template' => 'template-parts/components/content-find-anything-carousel.php',
'icon' => 'editor-textcolor',
'keywords' => array( 'find', 'search', 'lenses', 'anything'),
'category' => 'design',
'enqueue_assets' => function(){
wp_enqueue_style( 'slick', 'https://cdn.jsdelivr.net/npm/@accessible360/accessible-slick@1.0.1/slick/slick.min.css', array(), '1.8.1' );
wp_enqueue_style( 'slick-theme', 'https://cdn.jsdelivr.net/npm/@accessible360/accessible-slick@1.0.1/slick/accessible-slick-theme.min.css', array(), '1.8.1' );
wp_enqueue_script( 'slick', 'https://cdn.jsdelivr.net/npm/@accessible360/accessible-slick@1.0.1/slick/slick.min.js', array('jquery'), '1.8.1', true );
wp_enqueue_script( 'custom-scripts', get_stylesheet_directory_uri() . '/assets/src/carousel/index.js', array(), false, true );
},
));
This is GSAP which does not
acf_register_block_type(array(
'name' => 'lig_large_accordion',
'title' => __('LIG large Accordion'),
'description' => __('LIG Large Accordion'),
'render_template' => 'template-parts/blocks/content-large-accordion.php',
'icon' => 'editor-textcolor',
'keywords' => array( 'accordion', 'toggle', 'expand', 'info'),
'category' => 'design',
'enqueue_assets' => function(){
wp_enqueue_script( 'gsap-js', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.7.0/gsap.min.js', array(), false, true );
},
));
Update:
So it happens that one of the pages the block is used on is the home page, so I have this working:
function mytheme_enqueue_front_page_scripts() {
if( is_front_page() )
{
wp_enqueue_script( 'gsap-js', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.7.0/gsap.min.js', null, true );
}
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_front_page_scripts' );
Is there a way to also use it on one other page by page id?