Wordpress - Deregister custom post types

Currently there is not a function for unregistering a post type, the process however is quite simple.

Andrew Nacin provided some code over on trac, found here and posted below.

if ( ! function_exists( 'unregister_post_type' ) ) :
function unregister_post_type( $post_type ) {
    global $wp_post_types;
    if ( isset( $wp_post_types[ $post_type ] ) ) {
        unset( $wp_post_types[ $post_type ] );
        return true;
    }
    return false;
}
endif;

Unregistering a built-in post type will have unknown effects on WordPress, so please do so at your own risk. Unregistering a custom post type should be perfectly safe, but would naturally do no cleanup on your installation(ie. unregistering a post type does not equate to data removal from the database).

I can imagine a few scenarios where this could be required, but the more sensible approach(where possible), would be to simply not register the post type in the first place if it's not wanted.


As of WordPress 4.5 there is function to do that, unregister_post_type. Example:-

function delete_post_type(){
    unregister_post_type( 'blocks' );
}
add_action('init','delete_post_type');

This worked for me, like Rarst said using the remove_action() if possible.

add_action( 'after_setup_theme','remove_foundation_options', 100 );

function remove_foundation_options() {   
    remove_action( 'init', 'Orbit');    
}