manage_{$this->screen->taxonomy}_custom_column
云策文档标注
概述
manage_{$this->screen->taxonomy}_custom_column 是一个动态过滤器钩子,用于自定义分类法术语列表表中的列显示内容。它允许开发者根据列名和术语ID输出自定义HTML或数据。
关键要点
- 钩子名称是动态的,基于当前分类法的slug,例如 manage_category_custom_column 或 manage_post_tag_custom_column。
- 接受三个参数:$string(自定义列输出,默认为空)、$column_name(列名)和 $term_id(术语ID)。
- 通常与 manage_edit-{$taxonomy}_columns 过滤器配合使用,以添加自定义列。
代码示例
// 为自定义分类法“genre”添加列内容
add_action( 'manage_genre_custom_column', 'wpdocs_show_genre_meta_info_in_columns', 10, 3 );
function wpdocs_show_genre_meta_info_in_columns( $string, $columns, $term_id ) {
switch ( $columns ) {
case 'characterization' :
echo esc_html( get_term_meta( $term_id, 'genre-characterization', true ) );
break;
}
}注意事项
- 确保钩子名称中的分类法slug正确,例如对于自定义分类法“genre”,使用 manage_genre_custom_column。
- 此钩子主要用于输出内容,而非修改列结构;列结构应通过 manage_edit-{$taxonomy}_columns 过滤器定义。
原文内容
Filters the displayed columns in the terms list table.
Description
The dynamic portion of the hook name, $this->screen->taxonomy, refers to the slug of the current taxonomy.
Possible hook names include:
manage_category_custom_columnmanage_post_tag_custom_column
Parameters
$stringstring-
Custom column output. Default empty.
$column_namestring-
Name of the column.
$term_idint-
Term ID.
Source
return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
Skip to note 2 content
laurencebahiirwa
Suppose you have a custom taxonomy called “genre”, replace
{$this->screen->taxonomy}with the name of the custom taxonomy i.e. “genre”// Add info to the new columns add_action( 'manage_genre_custom_column', 'wpdocs_show_genre_meta_info_in_columns', 10, 3 ); function wpdocs_show_genre_meta_info_in_columns( $string, $columns, $term_id ) { switch ( $columns ) { // in this example, we had saved some term meta as "genre-characterization" case 'characterization' : echo esc_html( get_term_meta( $term_id, 'genre-characterization', true ) ); break; } }The sample below is for adding the column title in the same taxonomy.
add_filter( 'manage_edit-genre_columns', 'wpdocs_add_new_genre_columns' ); function wpdocs_add_new_genre_columns( $columns ) { $columns['characterization'] = __( 'Characterization' ); return $columns; }