Created
April 19, 2023 11:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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