You can do it like this (put in your functions.php
) :
function add_admin_scripts( $hook ) {
global $post;
if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
if ( 'recipes' === $post->post_type ) {
wp_enqueue_script( 'myscript', get_stylesheet_directory_uri().'/js/myscript.js' );
}
}
}
add_action( 'admin_enqueue_scripts', 'add_admin_scripts', 10, 1 );
Related Posts:
- Unregister post type from child theme
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- With what hook can I address all posts from all custom post types when they are published?
- How to localize value of posts
- What hook should be used to programmatically create a post only when master post is updated?
- How to register custom post types in a plugin?
- Remove “Get Shortlink” button in admin of custom post type
- Can’t unregister parent theme’s CPT from my child theme
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- Filter Posts from the Main Query
- Use remove_meta_box conditionally on custom post type
- wp_trash_post action hook with custom post type
- How do I amend form data before it is saved for a custom post type
- How to recover the post ID earlier in the WP admin hook action “firing” sequence?
- Using `set_transient()` when saving a custom post type
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- How to store additional data that is related to core data
- How to make sure, that only the selected post is changing?
- do action inside a class is not working
- Create action running on trashed_post hook to modify post_meta value
- Load a script just to custom post type in admin
- remove custom post type permalink
- How to Debug the ‘save_post’ Action?
- How to change “Draft” string for status of custom post type to “Unavailable”?
- Custom post type save_post action not firing
- How to correctly get post type in a the_title filter
- How to add a button to custom post type’s posts-page
- Why The Init Hook For Custom Post Types
- How to hook into the CPT’s title placeholder?
- Correct place to register and enqueue scripts
- Why get_next_post_link() or get_previous_post_link() doesn’t return the required links?
- How to set a custom post type post as static front page?
- WordPress Custom Shortcode Conflicting with Media Library
- Hook when adding or editing a specific custom post type? [closed]
- remove_action conditionally for Custom Post Type
- WordPress custom post action hook
- Custom Scripts per page or Custom Post Type
- Creating a function that receives the taxonomy terms that have been changed in a custom post type
- Add information above a custom post type listing of all posts page
- Using pre_get_posts to Filter Posts
- WordPress Rest API only returns content when posttype has editor capability
- update_post_meta() whenever custom post type is updated
- How to get Custom Post ID by adding filter to child theme’s function
- Custom Blog Post Listing in Genesis Sample Child Theme
- Set a default category – if the user didn’t select one- before creating a post
- Same Conditionals Not Working on Two Different Hooks
- Modifying date filter on admin page for custom post type to link to custom field
- WP CLI Get all Enqueued Scripts and Styles
- Validate custom fields before save using WordPress Rest API
- Storing posts from query and accessing later via AJAX call
- Push metadata in array
- Custom post type unintentionally called in every page
- Displaying custom taxonomy in the admin list of a custom post type
- Can taxonomies of custom post types be used with category actions?
- Dynamic Custom Fields
- Multiple Frontend Filters Using Advanced Custom Fields
- jQuery does not work
- Using preg_replace to filter custom textarea
- How can I add a filter to a particular post format?
- Is there any way to get list of all possible filter hooks for all post types?
- Create new custom post and post category of same name
- Combine multiple getEntityRecords calls
- Custom Post Type Slick Slider “$ is not a function”
- Deactivate JS Script in Plugin Shortcode
- Plugin Scripts no loading on options page
- Add an Outside Wrapper to my Header and Make it Full Width
- What do the numbers mean at the end of add_action(‘save_post’)…?
- Running a wordpress action when a custom post type term (taxonomy category) is changed
- How check if a post is saved from backend or frontend?
- ACF for custom post type archive pages: which hook to use?
- Get data from PHP to JavaScript to set position of each post on front page
- WordPress hook which triggers on post import
- Assigning alternate single-{cpt} template based on blog_id in multisite
- Before saving post hook
- Creating alternate meta box context locations
- Loading multiple post content in FancyBox
- add_action ‘init’ from inside a class for custom post types
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- Limiting actions only to edit.php page for specific custom post type
- How can I put content before my custom post type default pages?
- Dequeue styles with query doesn’t work
- Plugin Development using classes – Public & Private Callbacks
- URL issue retrieving Custom Post Types using Backbone JS API
- Store a value in global scope after init hook is fired
- Dynamic page for nav items used as filters
- How to use posts as tabs in a custom page?
- Post Click Redirect to Custom URL instead of Single Post Page
- Hide the update button from edit view in wordpress custom post type
- Hook create / update post
- dynamic vue widget inside custom post
- publish_post action callback not executed, why?
- call a function when insert and update a custom post type
- Move jQuery on *top* of footer
- Filter wp_dropdown_categories Per Post Type
- Hook only specific post type
- Custom post type functions.php if statement on action
- JavaScript file successfully registered but does not render correctly
- add comments custom fields after user is logged in
- Use add_action to run a script, but only on the post editor page
- Modifying post_type_link hook messing up edit function for a custom post