Skip to content

Commit

Permalink
Update get-started-with-wp-scripts.md
Browse files Browse the repository at this point in the history
@ndiego Hereby the changes.
  • Loading branch information
RVledder authored Nov 19, 2024
1 parent cf59c28 commit 2a83b36
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/getting-started/devenv/get-started-with-wp-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 2a83b36

Please sign in to comment.