Hook when adding or editing a specific custom post type? [closed]

There is admin_enqueue_scripts():

admin_enqueue_scripts is the first action hooked into the admin scripts actions. This hook provides a single parameter, the $hook_suffix for the current admin page. And it’s an action it can only be used to callback a specified function.

Usage like:

add_action( 'admin_enqueue_scripts', 'function_name' );

The codex page provides even an example on how to target a specific admin page:

function wpse162680_enqueue_script( $hook ) {
    $screen = get_current_screen();
    if ( $hook == 'post.php' && $screen->post_type != 'your-custom-posttype' ) {
        return;
    }
    wp_enqueue_script( 'my_custom_script', plugin_dir_url( __FILE__ ) . 'myscript.js' );
}
add_action( 'admin_enqueue_scripts', 'wpse162680_enqueue_script' );

Read Admin Screen Reference on how to target the right screen.


Note: About the other part of your question, maybe Post Status Transitions will help to there, but actually I’m not sure what you want to achieve.

Leave a Comment