There is a filter called register_taxonomy_args
in WP v4.4 that’s a big help here. This tested and working example assumes that the post types schools
and productions
have already been created.
/**
* Filter the arguments for registering a taxonomy.
*
* @since 4.4.0
*
* @param array $args Array of arguments for registering a taxonomy.
* @param string $taxonomy Taxonomy key.
* @param array $object_type Array of names of object types for the taxonomy.
*/
add_filter( 'register_taxonomy_args', 'wpse238461_taxonomy_school_subjects_title_changer', 10, 3 );
function wpse238461_taxonomy_school_subjects_title_changer( $args, $taxonomy, $object_type ) {
// We'll need to figure out what kind of post type we're looking at, and it's too early for other methods.
if ( ! isset( $_GET['post_type'] ) || ! $_GET['post_type'] ) {
return $args;
}
$post_type = $_GET['post_type'];
/*
// Bonus code for anyone trying to do this on regular post or page edit screens,
// $_GET['post_type'] is not set, so do something like this instead of/in addition to the above check
// We'll need to figure out what kind of post type we're looking at, and it's too early for other methods.
if ( ! isset( $_GET['post'] ) || ! $_GET['post'] ) {
return $args;
}
// Get the post type (post or page), bail if we can't.
$post_type = get_post_type( $_GET['post'] );
if ( ! $post_type ) {
return $args;
}
*/
// Make sure we're looking at the right taxonomy since this filter runs for all of them.
if ( 'school_subjects' !== $taxonomy ) {
return $args;
}
// Check if we're viewing the appropriate post type, and modify the label.
if ( 'schools' === $post_type ) {
$args['labels']['name'] = _x( 'Subject Wishlists', 'taxonomy general name', 'textdomain' );
// Alternate example for when taxonomy is using the label argument instead of the entire labels argument:
// $args['label'] = 'Subject Wishlist';
}
return $args;
}
// Taxonomy registration code
add_action( 'init', 'create_taxonomy_school_subjects' );
function create_taxonomy_school_subjects() {
register_taxonomy(
'school_subjects',
array( 'schools', 'productions' ),
array(
//'label' => __( 'School Subjects' ),
'labels' => array(
'name' => _x( 'School Subjects', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'School Subject', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search School Subjects', 'textdomain' ),
'all_items' => __( 'All School Subjects', 'textdomain' ),
'parent_item' => __( 'Parent School Subject', 'textdomain' ),
'parent_item_colon' => __( 'Parent School Subject:', 'textdomain' ),
'edit_item' => __( 'Edit School Subject', 'textdomain' ),
'update_item' => __( 'Update School Subject', 'textdomain' ),
'add_new_item' => __( 'Add New School Subject', 'textdomain' ),
'new_item_name' => __( 'New School Subject Name', 'textdomain' ),
'menu_name' => __( 'School Subjects', 'textdomain' ),
),
'rewrite' => array( 'slug' => 'school_subjects' ),
'hierarchical' => true,
)
);
}