Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_file_icon

Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

This hook is used for altering the HTML for a file displayed with a file upload field when editing your form.

Usage

add_filter('frm_file_icon', 'frm_file_icon', 10, 2);
function frm_file_icon($html, $atts){

Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.

Parameters

  • $html (string): The HTML to display
  • $atts (array): Includes image from wp_get_attachment_image and 'media_id'

Examples

Default output

This example will return the HTML the way is it generated by default.

add_filter('frm_file_icon', 'frm_file_icon', 10, 2);
function frm_file_icon($html, $atts){
   $image = $atts['image'];
   $media_id = $atts['media_id'];

   if ( $image && ! preg_match("wp-content/uploads/", $image) ) { //if this is a mime type icon
      $attachment = get_post($media_id);
      $label = basename($attachment->guid);
      $image .= " <span id='frm_media_$media_id' class='frm_upload_label'><a href='". wp_get_attachment_url($media_id) ."'>$label</a></span>";
   } else if ( $image ) {
      $image = '<a href="'. wp_get_attachment_url($media_id) .'">'. $image .'</a>';
   }
  return $image;
}

Add label on all files

add_filter('frm_file_icon', 'frm_file_icon', 10, 2);
function frm_file_icon($html, $atts){
   $image = $atts['image'];
   $media_id = $atts['media_id'];
   $attachment = get_post($media_id);
   $label = basename($attachment->guid);

   //if this is a mime type icon
   if ( $image && ! preg_match("wp-content/uploads/", $image) ) {
      $image = " <span id='frm_media_$media_id' class='frm_upload_label'><a href='". wp_get_attachment_url($media_id) ."'>$label</a></span>";
   } else if ( $image ) {
      $image = '<a href="'. wp_get_attachment_url($media_id) .'">'. $image . $label .'</a>';
   }
  return $image;
}
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2025 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Special offer unlocked.
    Get 55% OFF!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms