{$taxonomy}_edit_form_fields
云策文档标注
概述
这是一个 WordPress 动作钩子,在编辑分类法术语的表单字段显示后触发。钩子名称包含动态部分 $taxonomy,允许针对特定分类法进行定制。
关键要点
- 钩子名称格式为 {$taxonomy}_edit_form_fields,例如 category_edit_form_fields 或 post_tag_edit_form_fields
- 参数包括 $tag(WP_Term 对象,当前术语)和 $taxonomy(字符串,当前分类法 slug)
- 自 WordPress 3.0.0 版本引入,用于在编辑术语页面添加自定义字段或修改现有字段
代码示例
// 示例:为分类法添加自定义元字段(如 category)
$prefix_taxonomy = 'category';
function wporg_prefix_add_meta_fields() {
?>
<div class="form-field">
<label for="wporg_field">Custom Field</label>
<input type="text" name="wporg_field[]" id="wporg_field" value="">
<p class="description">Description for custom field.</p>
</div>
<?php
}
add_action('category_edit_form_fields', 'wporg_prefix_add_meta_fields');注意事项
- 钩子名称中的 $taxonomy 必须替换为实际分类法 slug,以确保正确触发
- 用户贡献笔记提供了添加自定义元字段和使用 WP 编辑器增强描述字段的实用示例,但需注意代码适配性和安全性
原文内容
Fires after the Edit Term form fields are displayed.
Description
The dynamic portion of the hook name, $taxonomy, refers to the taxonomy slug.
Possible hook names include:
category_edit_form_fieldspost_tag_edit_form_fields
Parameters
$tagWP_Term-
Current taxonomy term object.
$taxonomystring-
Current taxonomy slug.
Source
do_action( "{$taxonomy}_edit_form_fields", $tag, $taxonomy );
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
Skip to note 3 content
Mahdi Yazdani
Adding custom meta fields to a taxonomy.
Note that in this example name of the input is set to be an array. If the field name was not an array, then you’d have to save each field individually.
Skip to note 4 content
rscmasa
Adding WP editor to default description field: