Deregister custom post types

Anyone know of a way to deregister custom post types?

Is there an equivalent to register_post_type()?

Related posts

Leave a Reply

5 comments

  1. 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.

  2. As t31os noted it is easy to remove post type from global variable.

    But if you mean non-core post type then it would be better to lookup code that registers it and unhook with remove_action() (if it is decent code it should be hooked rather than run directly).

  3. In WordPress version 4.5 and above they provide a function to remove post type (unregister_post_type).
    Example

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

    It will work definately.