Anyone know of a way to deregister custom post types?
Is there an equivalent to register_post_type()
?
Anyone know of a way to deregister custom post types?
Is there an equivalent to register_post_type()
?
You must be logged in to post a comment.
As of WordPress 4.5 there is function to do that,
unregister_post_type
. Example:-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.
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.
This worked for me, like Rarst said using the remove_action() if possible.
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).In WordPress version 4.5 and above they provide a function to remove post type (unregister_post_type).
Example
It will work definately.