Skip to content

Instantly share code, notes, and snippets.

@michael-sumner
Created April 19, 2023 11:49
Show Gist options
  • Save michael-sumner/8a9627cff329f67cc3ee65621f2a6c4a to your computer and use it in GitHub Desktop.
Save michael-sumner/8a9627cff329f67cc3ee65621f2a6c4a to your computer and use it in GitHub Desktop.
You can load the script of the block within the php file
<?php
/**
* Block markup
*
* @package MyNamespace\Blocks\MyBlock
*
* @var array $attributes Block attributes.
* @var string $content Block content.
* @var WP_Block $block Block instance.
* @var array $context Block context.
*/
if ( ! wp_script_is( 'my-script-example' ) ) {
wp_enqueue_script(
'my-script-example',
'https://example.com/script.js',
Utility\get_asset_info( 'my-block', 'dependencies' ),
Utility\get_asset_info( 'my-block', 'version' ),
true
);
}
?>
<div <?php echo get_block_wrapper_attributes(); // phpcs:ignore ?>>
...
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment