Filters the attachment fields to edit.
Parameters
Source
$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
Changelog
Version | Description |
---|---|
2.5.0 | Introduced. |
Filters the attachment fields to edit.
$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
Version | Description |
---|---|
2.5.0 | Introduced. |
You must log in before being able to contribute a note or feedback.
This is the way to add custom fields to attachments:
Example migrated from Codex:
The following example adds a “Location” field for all attachments. This example also uses the “edit_attachment” action hook to save the submitted custom attachment form fields value to the post meta of the post in which the attachment belongs.
If you add a custom field to attachments as described above, the field will be displayed and saved as well. But: There is no complete Ajax feedback to the user: the save icon appears in the top-right corner. “attachment-details” gets the class “save-waiting”, then again “save-ready”. The class “save-complete” is omitted. For the standard fields again this status is displayed. The text “Saved.” appears. This should be displayed for custom fields, too!
There are “text” and “textarea” field types that can be used by default. To have another field type, you can simply use the “html” type. Here is an example of how to add a button: