Skip to content

Instantly share code, notes, and snippets.

@JMWebDevelopment
Created April 20, 2018 21:51
Show Gist options
  • Save JMWebDevelopment/9715e555a46be1c65584e86e129df865 to your computer and use it in GitHub Desktop.
Save JMWebDevelopment/9715e555a46be1c65584e86e129df865 to your computer and use it in GitHub Desktop.
function sports_bench_blocks_editor_scripts() {
// Make paths variables so we don't write em twice ;)
$blockPath = 'js/editor.blocks.js';
$editorStylePath = '/css/blocks.editor.css';
// Enqueue the bundled block JS file
wp_enqueue_script(
'sportsbench-blocks-js',
plugins_url( $blockPath, __FILE__ ),
[ 'wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-api' ],
filemtime( plugin_dir_path(__FILE__) . 'js/editor.blocks.js' )
);
// Enqueue optional editor only styles
wp_enqueue_style(
'jsforwp-blocks-editor-css',
plugins_url( $editorStylePath, __FILE__),
[ 'wp-blocks' ],
filemtime( plugin_dir_path( __FILE__ ) . $editorStylePath )
);
}
// Hook scripts function into block editor hook
add_action( 'enqueue_block_editor_assets', 'sports_bench_blocks_editor_scripts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment