Use register_post_type() to modify an existing post type

There are lots of situations where a theme or plugin registers a post type and you want to modify it. There is of course add_post_type_support() and remove_post_type_support(), but those don’t give access to the full list of arguments that register_post_type() takes. In particular, maybe I want to disable a post type archive, hide the admin UI, hide from search, etc. while leaving the rest of the post type settings alone.

The Codex page for register_post_type() dangles this in front of me:

Description

Create or modify a post type.

But in the past, when I’ve try to do this, it hasn’t seemed to work. Is this function really for modifying post types, and if so, can you simply redeclare a couple arguments and leave the rest alone?

Seeing that there isn’t even a deregister_post_type() function, I don’t understand how it can be done.

6

Is this function really for modifying post types

Yes.

and if so, can you simply redeclare a couple arguments and leave the rest alone?

No. If you want to modify arguments to a post type, you need to use get_post_type_object to get the post type object, modify what you want in it, then re-register it using your modified type as the new $args parameter.

Leave a Comment