Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

At WP Front-end I create a upload form for users.

That form has three input fields (title, tags and upload).

So I want to add "Title - Tag - file_name" as alt attribute for images during the file upload.

How can I do with my code below?

if ($gui == 'upload') {
    if (!function_exists('wp_generate_attachment_metadata')){
        require_once(ABSPATH . "wp-admin" . '/includes/image.php');
        require_once(ABSPATH . "wp-admin" . '/includes/file.php');
        require_once(ABSPATH . "wp-admin" . '/includes/media.php');
    if ($_FILES) {
       foreach ($_FILES as $file => $array) {
           if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
              return "Upload Err: " . $_FILES[$file]['error'];
           $attach_id = media_handle_upload( $file, $newPost );
   if ($attach_id > 0){
       //and if you want to set that image as Post  then use:
share|improve this question
First, better use admin_url(). Second, how exactly is the alt-HTML tag displayed? Does it come from caption, or something else? HInt: There's no alt-Tag in the meta data. –  kaiser Jul 11 '13 at 11:11
An alt attribute must be a meaningful, functional replacement for an image. File names are the opposite. –  toscho Jul 11 '13 at 15:11
add comment

Your Answer


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

Browse other questions tagged or ask your own question.