From 2a83b36332c1aaa18813720ac4833836e480ca8d Mon Sep 17 00:00:00 2001 From: Remi Vledder Date: Tue, 19 Nov 2024 16:22:16 +0100 Subject: [PATCH] Update get-started-with-wp-scripts.md @ndiego Hereby the changes. --- .../devenv/get-started-with-wp-scripts.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/getting-started/devenv/get-started-with-wp-scripts.md b/docs/getting-started/devenv/get-started-with-wp-scripts.md index 16f1bbc6015b5..ba5485ba8fa69 100644 --- a/docs/getting-started/devenv/get-started-with-wp-scripts.md +++ b/docs/getting-started/devenv/get-started-with-wp-scripts.md @@ -80,7 +80,23 @@ A `build/index.asset.php` file will also be created in the build process, which ### Enqueuing assets -If you register a block via `register_block_type` the scripts defined in `block.json` will be automatically enqueued (see [example](https://github.com/WordPress/block-development-examples/tree/trunk/plugins/minimal-block-ca6eda)) +If you register a block via `register_block_type` the scripts defined in `block.json` will be automatically enqueued: + +```php +/** + * Register the block. + */ +function example_register_block() { + // The build folder contains the block.json file. + register_block_type( __DIR__ . '/build' ); +} + +add_action( 'init', 'example_register_block' ); +``` + +View the complete [example](https://github.com/WordPress/block-development-examples/tree/trunk/plugins/minimal-block-ca6eda) in context. + +Using this approach will register the block on the server. More information regarding the registering of a block can be found in [Registration of a block](https://developer.wordpress.org/block-editor/getting-started/fundamentals/registration-of-a-block/). To manually enqueue files in the editor, in any other context, you can refer to the [Enqueueing assets in the Editor](https://developer.wordpress.org/block-editor/how-to-guides/enqueueing-assets-in-the-editor/) guide for more information, but here's a typical implementation.