Skip to content

Instantly share code, notes, and snippets.

@nicmare
Created October 11, 2022 13:59
Show Gist options
  • Save nicmare/1faa52cb3f699c780725c5935e49bf15 to your computer and use it in GitHub Desktop.
Save nicmare/1faa52cb3f699c780725c5935e49bf15 to your computer and use it in GitHub Desktop.
<?php
// conditionally load sal.js assets
function lmdm_animation_scripts(){
if(is_singular()) {
$blocks = parse_blocks(do_shortcode(get_post(get_the_ID())->post_content));
if(is_array($blocks)){
foreach($blocks as $block){
if(isset($block["attrs"]["effect"]) && !empty($block["attrs"]["effect"])){
wp_enqueue_style('saljs-style', get_stylesheet_directory() . '_js/saljs/sal.css');
wp_enqueue_script('lmdm-saljs', get_stylesheet_directory() . '_js/saljs/sal.js', null, "1.0");
wp_add_inline_script("lmdm-saljs", "window.addEventListener('load', () => { sal({ threshold: 0.5 }); });");
}
}
}
}
}
add_action( 'wp_enqueue_scripts', 'lmdm_animation_scripts',100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment