Using WordPress ‘registered_taxonomy_{$taxonomy}’ PHP action

The registered_taxonomy_{$taxonomy} WordPress PHP action is triggered after a specific taxonomy is registered. The dynamic part of the action name, $taxonomy, represents the taxonomy key.

Usage

add_action('registered_taxonomy_{$taxonomy}', 'your_custom_function', 10, 3);

function your_custom_function($taxonomy, $object_type, $args) {
    // Your custom code here

}

Parameters

  • $taxonomy: (string) Taxonomy slug.
  • $object_type: (array|string) Object type or array of object types.
  • $args: (array) Array of taxonomy registration arguments.

More information

See WordPress Developer Resources: registered_taxonomy_{$taxonomy}

Examples

Log registered taxonomies

Log the registered taxonomy details to a debug file.

add_action('registered_taxonomy_{$taxonomy}', 'log_registered_taxonomy', 10, 3);

function log_registered_taxonomy($taxonomy, $object_type, $args) {
    // Log registered taxonomy details
    error_log("Taxonomy: {$taxonomy} | Object Type: " . print_r($object_type, true) . " | Args: " . print_r($args, true));
}

Add a custom field to a specific taxonomy

Add a custom field to the ‘location’ taxonomy registration.

add_action('registered_taxonomy_location', 'add_custom_field_to_location', 10, 3);

function add_custom_field_to_location($taxonomy, $object_type, $args) {
    // Add a custom field to the 'location' taxonomy
    $args['meta_box_cb'] = 'custom_location_meta_box';
    register_taxonomy($taxonomy, $object_type, $args);
}

Modify labels for ‘category’ taxonomy

Change the labels for the ‘category’ taxonomy.

add_action('registered_taxonomy_category', 'modify_category_labels', 10, 3);

function modify_category_labels($taxonomy, $object_type, $args) {
    // Change labels for the 'category' taxonomy
    $args['labels'] = array(
        'name' => 'Custom Categories',
        'singular_name' => 'Custom Category'
    );
    register_taxonomy($taxonomy, $object_type, $args);
}

Restrict taxonomy to specific post types

Restrict the ‘skills’ taxonomy to be only used with the ‘portfolio’ post type.

add_action('registered_taxonomy_skills', 'restrict_skills_taxonomy_to_portfolio', 10, 3);

function restrict_skills_taxonomy_to_portfolio($taxonomy, $object_type, $args) {
    // Restrict 'skills' taxonomy to 'portfolio' post type
    register_taxonomy($taxonomy, 'portfolio', $args);
}

Add custom capabilities to a taxonomy

Add custom capabilities to the ‘department’ taxonomy.

add_action('registered_taxonomy_department', 'add_custom_capabilities_to_department', 10, 3);

function add_custom_capabilities_to_department($taxonomy, $object_type, $args) {
    // Add custom capabilities to the 'department' taxonomy
    $args['capabilities'] = array(
        'manage_terms' => 'manage_departments',
        'edit_terms' => 'edit_departments',
        'delete_terms' => 'delete_departments',
        'assign_terms' => 'assign_departments'
    );
    register_taxonomy($taxonomy, $object_type, $args);
}