Using entrypoints
Last updated
Was this helpful?
Last updated
Was this helpful?
If you get deeper into plugin development you will notice that some frontend coding is not needed for all pages. Some scenarios:
Gutenberg block: Only load JS / CSS when the Gutenberg block is loaded
Shortcode: Only load JS / CSS when the Gutenberg block is loaded
Widget: A "big" widget should outsource coding to its own entrypoint
WP Admin page: Each page should only load their JS / CSS
The boilerplate and example implementations use the simplest scenario and loads a single admin.js
on wp-admin
and widget.js
on the website itself.
For this, you should consider conditional loading of JS / CSS files. Let's go with an example, which should only be loaded on wp-admin/edit.php
. Now, how to create a new entrypoint? In our boilerplate context, an "entrypoint" is each file in (first level, no sub folders). Create a new file :
Afterwards run and the new entrypoint edit.js
is compiled to . Open and add this: