I’ve got JavaScript that verifiably loads on the post type edit page
But did you enqueue your script with the correct dependencies? Have you checked the browser console? Did it say something like “Uncaught TypeError: Cannot read property ‘createElement’ of undefined“?
The JavaScript code in the question requires the @wordpress/element
and @wordpress/hooks
packages, which are available as registered (JavaScript) scripts in WordPress with wp-<the package name without the @wordpress/ part>
as the script handle/identifier, e.g. wp-element
for @wordpress/element
and wp-hooks
for @wordpress/hooks
, so make sure your script has at least those dependencies.
wp_enqueue_script( 'your-script', '/path/to/your-script.js', [ 'wp-element', 'wp-hooks' ] );
Or you can also use block-editor
, blocks
, components
, etc., which its dependencies include both wp-element
and wp-hooks
, as a dependency for your script.
See wp_default_packages_scripts()
for the other (core/Gutenberg) script handles you can use.