WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

with the code from this question:

run ok, but I need add one input line to write the title of the file attach and save this title in media when upload this file.

share|improve this question

First add to your for the new input field:

<form id="file-form" enctype="multipart/form-data" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
    <p id="async-upload-wrap">
        <label for="async-upload">upload</label>
        <input type="file" id="async-upload" name="async-upload"> <input type="submit" value="Upload" name="html-upload">
    <p id="image_title">
        <label for="image_title">Image Title</label>
        <input type="text" id="image_title" name="image_title" value="">
        <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id ?>" />
        <?php wp_nonce_field('client-file-upload'); ?>
        <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
        <input type="submit" value="Save all changes" name="save" style="display: none;">

then after you save the image and get an attachment id you can update the attachment metadata:

if ($_FILES) {
    foreach ($_FILES as $file => $array) {
        $newupload = insert_attachment($file,$post_id);
        //get the meta data of the attachment 
        $meta = wp_get_attachment_metadata( $newupload);
        //set the title
        $meta['image_meta']['title'] = wp_kses($_POST['image_title']);
        //update the attachment with the new title.
share|improve this answer
I used this code and file is upload but the title is equal to filename. – Fontepink Sep 19 '11 at 8:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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