我知道已经有了一个公认的答案,但这里有另一种方法可以使用挂钩完成同样的事情。
//* Make sure we\'re on the load edit tags admin page
add_action( \'load-edit-tags.php\', \'wpse_262299_edit_tags\' );
add_action( \'load-term.php\', \'wpse_262299_edit_tags\' );
function wpse_262299_edit_tags() {
//* Return early if not the news post type
if( \'news\' !== get_current_screen()->post_type ) {
return;
}
$taxonomies = [ \'news-category\', \'other-taxonomy\' ];
//* Add actions to $taxonomy_pre_add_form and $taxonomy_pre_edit_form
array_filter( $taxonomies, function( $taxonomy ) {
add_action( "{$taxonomy}_pre_add_form", \'wpse_262299_enqueue_style\' );
add_action( "{$taxonomy}_pre_edit_form", \'wpse_262299_enqueue_style\' );
});
}
function wpse_262299_enqueue_style( $taxonomy ) {
//* All the logic has already been done, do enqueue the style
wp_enqueue_style( \'wpse-262299\', plugins_url( \'style.css\', __FILE__ ) );
}