Execution of JavaScript on save post

I got stuck with one problem, can somebody please help.. 🙂

I would like to execute custom JavaScript function before post is saved, and i can’t find how to do that.
Something like JavaScript version of save_post action hook 🙂

Thank you!

1 Answer
1

Do it like shown below, as suggested by @gyo and done by @Howdy_McGee in his answer.

function admin_queue( $hook ) {
    global $post; 
    if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
        if ( 'targeted-posttype' === $post->post_type ) { 
            wp_enqueue_script( 
                'custom-title-here', 
                bloginfo( 'template_directory' ) . '/scripts/custom-script.js', 
                'jquery', 
                '', 
                true 
            );
        }
    }
}
add_action( 'admin_enqueue_scripts', 'admin_queue' );

Leave a Comment