Deregister Custom Post Types in WordPress

Not all Custom Post Types registered by theme or plugins may not be needed. If your theme or plugins add custom post types that are unnecessary for your site you can deregister them easily without switching the theme or deactivating that plugin. Deregistering Custom Post Types from WordPress is easy and simple, follow the steps below to make it happen:

1) Create a Custom Functions Plugin or if you use a child theme, use its functions.php file.

2) Now, place the following codes in it:

<?php
/**
* function to deregister matching post types
*/
function unregister_custom_post_types() {
    global $wp_post_types;
    foreach( array( 'services', 'staffs', 'projects', 'testimonials' ) as $post_type ) {
        if ( isset( $wp_post_types[ $post_type ] ) ) {
            unset( $wp_post_types[ $post_type ] );
        }
    }
}

add_action( 'init', 'unregister_custom_post_types', 20 );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.