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
- Add a post when another post type is inserting
- Check Title Unique Or Not and If not error message and dont save
- 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
- Add html to cpt main page / admin edit.php
- Trying to add script to specific admin page is not working
- if custom posts type exists and there are posts load script
- register_taxonomy and register_post_type does not work [closed]
- WP CLI Get all Enqueued Scripts and Styles
- Hooking in to an archive page?
- Add custom column in custom post type edit page
- Open div inside a custom post-type with Fancybox
- Very simple wordpress block to display posts from an api call
- How to get the parent of a non-hierarchical custom post type being edited in Gutenberg
- Insert Multiple Post with Same Publish Button
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Validate custom fields before save using WordPress Rest API
- Enqueueing scripts and styles multiple CPTS
- When to use add_action when registering/enqueuing scripts
- Storing posts from query and accessing later via AJAX call
- Push metadata in array
- Custom post type unintentionally called in every page
- Posts are duplicating on wp_post_update
- Displaying custom taxonomy in the admin list of a custom post type
- Can taxonomies of custom post types be used with category actions?
- Save the post parent in a custom post type in Gutenberg
- Plugin – Combine Meta Box Input Fields into single saveble record
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- JS innerhtml changing style when using AJAX
- How do I add a custom screen for a custom post type to be called from custom post row action?
- Custom post type suppress transition from future to publish
- Side effects of Script and Iframe in post
- Limit number of custom posts per taxonomy
- Execute JavaScript in WordPress Hook
- Dynamic Custom Fields
- Multiple Frontend Filters Using Advanced Custom Fields
- Categorise Custom Post Types
- jQuery does not work
- Using preg_replace to filter custom textarea
- How can I add a filter to a particular post format?
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- 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
- Add a custom text to admin footer in a Custom Post Type page
- Extracting Address from Custom Post via Javascript for Google Maps API
- Get rid of “trash can” for custom post type
- Combine multiple getEntityRecords calls
- Custom Post Type Slick Slider “$ is not a function”
- Using wp_localize_script to get data from cpt and pass it to maplace-js locations
- Deactivate JS Script in Plugin Shortcode
- Custom Meta fields Update hook?
- Include php on a specific page template
- How do I add some javascript validation to the admin interface form’s onsubmit?
- 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
- custom fields cannt be seen with version 3.1
- sortable columns for multiple custom post types not working
- How check if a post is saved from backend or frontend?
- How to build a WordPress post review system beside commenting
- WordPress hook after post content and meta update
- 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
- providing access to post_id or post inside functions.php
- Before saving post hook
- Why is wp api returning old acf values?
- Creating alternate meta box context locations
- Make a custom column sortable by a value from a different custom post type
- Types plugin custom post add_action hooks
- Enqueueing TinyMCE
- wordpress post_where set only for my costum post type
- Loading plugin text domain before registering post type
- Loading multiple post content in FancyBox
- How can I get some of a posts meta data whilst it is still inserting?
- add_action ‘init’ from inside a class for custom post types