For example…
add_action('init', 'reg_tax');
function reg_tax() {
register_taxonomy_for_object_type('category', 'attachment');
}
Adds a “Category” input field to the media manager and attachments editor. I’d like to know if its possible to alter this function to capture a “link destination” URL instead. The URL would be executed when the image is clicked.
Also need to know how to retrieve the value for this new field.
UPDATE: Thanks to Thomas Answer below, here is my final solution…
function my_image_attachment_fields_to_edit($form_fields, $post) {
$form_fields["custom1"] = array(
"label" => __("Image Links To"),
"input" => "text",
"value" => get_post_meta($post->ID, "_custom1", true)
);
return $form_fields;
}
function my_image_attachment_fields_to_save($post, $attachment) {
if( isset($attachment['custom1']) ){
update_post_meta($post['ID'], '_custom1', $attachment['custom1']);
}
return $post;
}
add_filter("attachment_fields_to_edit", "my_image_attachment_fields_to_edit", null, 2);
add_filter("attachment_fields_to_save", "my_image_attachment_fields_to_save", null, 2);
I use a very rough plugin to add information about the artist and a URL to media files. It needs some tweaking (and I need the time), but it works and may demonstrate how add the extra fields and how to use them in your theme:
Responding to Drew’s question in the comments, you can customize the HTML for the field by setting the
input
to a new string, and then adding that same string as a key to the$form_fields
array.By default, WordPress will only accept
text
andtextarea
for theinput
type. Anything else will have to be defined in a custom way as below. I haven’t tried actually persisting form fields this way so in order to make another input type, like a radio button, might take a little extra finesse.