The registered_post_type_{$post_type} WordPress PHP action fires after a specific post type is registered.
Usage
add_action('registered_post_type_post', 'my_custom_function', 10, 2); function my_custom_function($post_type, $post_type_object) { // Your custom code here }
Parameters
- $post_type (string) – Post type key.
- $post_type_object (WP_Post_Type) – Arguments used to register the post type.
More information
See WordPress Developer Resources: registered_post_type_{$post_type}
Examples
Log registered post type
Log the registered post type to a custom log file.
add_action('registered_post_type_post', 'log_registered_post_type', 10, 2); function log_registered_post_type($post_type, $post_type_object) { error_log("Registered post type: {$post_type}\n", 3, '/path/to/your/log-file.log'); }
Modify the registered post type capabilities
Update the capabilities of a custom post type after it’s registered.
add_action('registered_post_type_my_custom_post_type', 'update_capabilities', 10, 2); function update_capabilities($post_type, $post_type_object) { $post_type_object->cap->publish_posts = 'publish_custom_posts'; }
Add support for a custom feature
Add support for a custom feature, such as a thumbnail, to a specific post type after it’s registered.
add_action('registered_post_type_my_custom_post_type', 'add_thumbnail_support', 10, 2); function add_thumbnail_support($post_type, $post_type_object) { add_post_type_support($post_type, 'thumbnail'); }
Remove support for a custom feature
Remove support for a custom feature, such as an excerpt, from a specific post type after it’s registered.
add_action('registered_post_type_my_custom_post_type', 'remove_excerpt_support', 10, 2); function remove_excerpt_support($post_type, $post_type_object) { remove_post_type_support($post_type, 'excerpt'); }
Add a custom taxonomy
Register a custom taxonomy for a specific post type after it’s registered.
add_action('registered_post_type_my_custom_post_type', 'register_custom_taxonomy', 10, 2); function register_custom_taxonomy($post_type, $post_type_object) { register_taxonomy('my_custom_taxonomy', $post_type, array( 'label' => __('My Custom Taxonomy'), 'rewrite' => array('slug' => 'my-custom-taxonomy'), 'hierarchical' => true, )); }