So, after an annoyingly long struggle, I discovered that I needed to have the script enqueued/registered with no dependencies. So in the end, to make it work, I needed this:
function add_admin_scripts( $hook ) {
global $post;
wp_register_script( 'sectioned_page_script', get_stylesheet_directory_uri() . '/js/sectioned_page.js' );
if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
if ( 'sectioned_page' === $post->post_type ) {
wp_enqueue_script( 'sectioned_page_script' );
}
}
}
add_action( 'admin_enqueue_scripts', 'add_admin_scripts', 10, 1 );
Related Posts:
- Prevent sorting and dragging of specific postbox metabox
- How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button
- Removing panels (meta boxes) in the Block Editor
- WordPress SEO by Yoast: Hide Meta Boxes in Posts for Non-admins
- How can I create a taxonomy meta-box with search suggestions but no new terms input?
- How to Add Reminders/Notes to New Post Meta Boxes
- How to reorder meta box position?
- How do I position meta_box on post edit screen after the title?
- Put the media uploader in a metabox
- Custom Meta Boxes: multiple fields within a repeatable field
- Metabox date month number to word
- get registered metaboxes by post type or post ID
- Remove metabox from specific page template in admin
- Is there a filter/action to add content to WP admin metaboxes?
- Attach Files Metabox
- How do I create a meta box for dates?
- esc before saving or before displaying does it matter?
- Add a meta description to home page?
- How to insert Gallery shortcode to a meta box
- Display list of tags as drop down menu or radio buttons in a meta box?
- How to List all Sidebars in a Metabox
- Set height of the categories meta box in post dashboard
- Add template meta box to category edit page?
- Get image captions for images on gallery post format metabox
- How do I migrate meta boxes from the Classic Editor to the “side area” in Gutenberg Editor?
- Adding Metaboxes – so much code is there a shorter DRY way?
- Consolidate Metaboxes into 1 Big Metabox
- I need a Simple image uploader with a simple screen. WP default has too many options.
- Show or hide custom meta box not work with Gutenberg
- TinyMCE with custom buttons on a meta box
- How do i hide the auto-generated custom field that’s created when update_post_meta() is called?
- Set the default value as checked for a meta box checkbox
- How to search by metadata using REST API
- Display oembed in repeatable metaboxs using CMB2
- Automatically add a tag according to custom metadata
- How to add categories to page editor?
- Having trouble getting my meta data to save
- Undefined ‘post_type’ error on Add new page
- Display meta box on front end
- Show how many images are attached to a post/page on compose page
- Metabox context for page post type
- How to use MarkDown in a custom textarea field?
- Problem with meta box in Links
- Post Meta not saving when have empty post
- Remove ShareDaddy meta box from Pages only
- How to modify Publish metabox?
- On click hide group of metabox, similar to screen options checkbox?
- Hide Polylang metabox from the post edit sidebar
- How to make a stand-alone button to the post edit view
- Controlling Meta Box Height
- wp_editor loses data, perhaps an html_entity_decode problem?
- How to list all tags as radio buttons in a meta box?
- how can i do metabox [closed]
- How to add meta box for image upload using WordPress media uploader?
- How to position user meta data field
- Display Content if Meta Checkbox is checked?
- why add_menu_page use simple function as arg while add_meta_box a call back?
- Output from Meta Box Array
- add_post_meta() & update_post_meta()
- How to show the value of specific key from nested array?
- MetaBox with Editor instead of textarea – html not saved [closed]
- Use meta boxes inside an archive page template for Woocommerce
- Why do Metabox use Nonces?
- conditionally echo in meta box data loop
- Hide Page Title with Post Meta
- Meta Box multi checkbox in template
- Show button if meta box has content, else hide
- Post Excerpt field only showing for default administrator
- remove a single post_meta
- Checkbox in post not saving value
- how to log in to WP if the “Log in” link under Meta is missing
- Custom loop attached to link
- Getting metabox value within a shortcode?
- Add metabox to pages that use custom template in WordPress
- Remove Username and just show Name in Author Metabox in backend
- Metabox not saving values
- Update Post Meta in Front End with a form
- How to Edit & Update meta_box values from Front-End user Form
- Metabox with checkbox is not working true!
- Displaying a Metabox linked to post settings for all users
- Can’t get meta values to save
- Error when adding Meta Boxes, but only when adding 3 with the same callback
- Is this Edit Post Screen?
- Custom meta box using OOP way doesn’t save data
- Using Meta Boxes in a Custom Page Template
- A correct hook for saving meta boxes data
- update_post_meta does not work
- Hooking into the Meta Boxes (Name/Web Address/Description) on the ‘Add New Link’ Page
- show title if one of post meta exist
- Query a Custom Post Type to another CPT via Metabox
- when saveing $meta_box i get Undefined index error
- Adding a Custom ‘Now’ button under ‘Published on’ header to return current date and time
- Adding meta boxes to custom post type
- Meta boxes not showing up
- Custom metabox with App Store / Google Play links
- Metaboxes not saving data
- How do I create a Meta box that can be repeated? (with an image section and text area)
- Need help, Passing variables with get_post_meta
- Input select option Change Content in Metabox
- Is there a way to remove the Add boxes from the Screen Options menu metabox?