How can deregister scripts for a certain custom post type?

My opinion, if you are the one registering and enqueing the scripts and styles, enqueue them conditionally. I don’t see any use enqueueing a scripts or styles just to dequeue them later on.

If you want to take the dequeue route, you need to

  • dequeue the script or style, not deregister it

  • Make sure your priority is correct, ie, you must dequeue the script or style after it is properly loaded. Doing this before the script or style is properly loaded wont work

EXAMPLE 1

add_action( 'wp_enqueue_scripts', 'enqueue_my_scripts' );
function enqueue_my_scripts()
{
    wp_register_script( 'my_script', /* Add the rest of your details*/ );
    if ( !is_singular( 'my_post_type' ) ) // If we are not on a single post page from my my_post_type, enqueue the script
        wp_enqueue_script( 'my_script' );
}

EXAMPLE 2

add_action( 'wp_enqueue_scripts', 'dequeue_my_scripts', 999 ); // Notice the priority
function dequeue_my_scripts()
{
    if ( is_singular( 'my_post_type' ) ) // If we are on a single post page from my my_post_type, dequeue the script
        wp_dequeue_script( 'my_script' );
}