Skip to content

Instantly share code, notes, and snippets.

@juliend2
Created May 4, 2012 12:20
Show Gist options
  • Save juliend2/2594493 to your computer and use it in GitHub Desktop.
Save juliend2/2594493 to your computer and use it in GitHub Desktop.
Return an icon image path for the given attachment ID
<?php
function get_icon_for_attachment($post_id) {
$base = get_template_directory_uri() . "/images/icons/";
$type = get_post_mime_type($post_id);
switch ($type) {
case 'image/jpeg':
case 'image/png':
case 'image/gif':
return $base . "image.png"; break;
case 'video/mpeg':
case 'video/mp4':
case 'video/quicktime':
return $base . "video.png"; break;
case 'text/csv':
case 'text/plain':
case 'text/xml':
return $base . "text.png"; break;
default:
return $base . "file.png";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment