Skip to content

Instantly share code, notes, and snippets.

@michaelwilhelmsen
Last active January 29, 2019 15:04
Show Gist options
  • Save michaelwilhelmsen/70749e9c696c7c800b1f5ee3abdcae7b to your computer and use it in GitHub Desktop.
Save michaelwilhelmsen/70749e9c696c7c800b1f5ee3abdcae7b to your computer and use it in GitHub Desktop.
This works even for flexible content fields. Just inspect the field in console when in admin and snab the data-key name from there.
<?php
add_action( 'wp_enqueue_scripts', 'sp_register_acf_field_scripts', 5 );
function sp_register_acf_field_scripts() {
// Plugin file
wp_register_script( 'siema-js', get_stylesheet_directory_uri() . '/bower_components/siema/dist/siema.min.js', array(), '', true );
// Custom functionality
wp_register_script( 'siema-init-js', get_stylesheet_directory_uri() . '/library/js/siema-init.js', array(), '', true );
}
/* Inspect ACF field in admin to get correct key name */
add_filter('acf/load_field/key=field_5922a0d922cce', 'sp_load_field_assets');
function sp_load_field_assets( $field ) {
wp_enqueue_script( 'siema-js' );
wp_enqueue_script( 'siema-init-js' );
return $field;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment