I'm developing a plugin, and, each time a user uploads an image in the media library, I'd like to modify metadata of this image. I have tried with the hook "wp_handle_upload_prefilter" but it seems this method doesn't work.

  • It is hard to answer such a question. What exactly do you want to modify and ehy the use of that hook wasn't good enough, what code did you use? Commented Dec 27, 2015 at 17:23
  • wordpress.stackexchange.com/a/212391/84219
    – jgraup
    Commented Dec 27, 2015 at 17:31
  • Indeed, it was with "wp_handle_upload". Thanks a lot :) For each image uploaded, I add metadata, with PHP (with iptcembed()) and it works fine ! :) But is it possible to do this, for each thumbnail generated ?
    – Clément
    Commented Dec 28, 2015 at 13:44

2 Answers 2


You need to use attachment_fields_to_save filter. There is nice example on codex. So instead of copying that here, I would rather like to point you towards the codex page. Please take a look here. I hope this helps.

  • I tried with "attachment_fields_to_save", but I think the function is not called, when I'm sending my image to the server :/
    – Clément
    Commented Dec 27, 2015 at 19:26

Use added_post_meta and update_post_meta with the $post_id. For extended properties see this post and this for more image functions.

add_action('added_post_meta', 'wpse_20151218_after_post_meta', 10, 4);

function wpse_20151218_after_post_meta($meta_id, $post_id, $meta_key, $meta_value) {

    if($meta_key === '_wp_attachment_metadata') {

        // Add Custom Field
        update_post_meta($post_id, '_example_meta_key', '1234567');

        $attachment_meta = get_post_meta($post_id);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.