WordPress has a native function wp_mime_type_icon()
in wp-includes/post.php
that you can use.
Basic example:
// $attachment should be a full post object
if ( wp_attachment_is_image( $attachment->ID ) )
{
echo wp_get_attachment_image(
$attachment->ID,
array( 480, 900 ),
FALSE,
array ( 'class' => 'aligncenter' )
);
}
else
{
echo '<img src="' . wp_mime_type_icon( $attachment->post_mime_type ) . '">';
}
Look in wp-includes/images/crystal/
for available file type icons:
- archive
- audio
- code
- default
- document
- interactive
- spreadsheet
- text
- video
You can set up your own image directory and filter 'icon_dir'
for the local path and 'icon_dir_uri'
for the URIs to let WordPress use your images.
To change just singular files filter 'wp_mime_type_icon'
:
apply_filters( 'wp_mime_type_icon', $icon, $mime, $post_id )
Related Posts:
- Personalized Gallery what are my options?
- Modified wp.media.view.Settings.Gallery in Backbone JS, but editing doesn’t work
- Rename UPLOADS folder with custom WP_CONTENT_DIR
- How to move wp-content (or uploads) outside of the WordPress directory
- Limit Media Library to Given Folder
- Customizing gallery shortcode in 3.5
- Gallery Shortcode: using link attribute to link to a specific image size
- Automatically wrap post image in div
- media_handle_upload weird thing
- Syncing Avatars across multisite
- How to re-arrange media uploaded using : media_handle_upload() as per year / month
- Hide upload image fields for the different media upload popups
- Customize the WordPress Default Gallery Output
- Best way to implement a thumbnail-based gallery in WordPress?
- How to insert a sitemap within a subsite when using WordPress multisite
- Gallery IDS and Captions: hide/show on a per ID basis
- Modify Gallery Output to render differently on a PAGE and a POST
- Add a InfoBox in the media upload window
- I’m using add_meta_box() but want to include TinyMCE editor *and* Media Uploads for each box
- Get ORIGINAL image links from get_post_gallery
- WordPress media uploader – upload tabs not hiding
- custom upload directory only for plugin uploads
- problem in uploading attachment to custom directory
- Installing new theme on running site
- Media Upload not working after hiding some elements from functions.php
- Customizing the gallery of the post correctly
- Custom default settings for WP native Gallery Block
- Can’t upload format files on media library
- Lightbox not showing image caption
- the temporary save folder is wrong
- Altered Media Library URLs
- How do I enable the text editer in my WordPress theme? [closed]
- Is there a way to limit multi upload in media upload box?
- Custom Link In WordPress Media “Attachment Details” Upload Screen
- How to customize the gallery shortcode in WordPress?
- How can I add a Description column to the media library browser screen?
- Upload files in wordpress
- Custom image sizes ignored in WP 3.5
- WordPress uploads directory. Featured Images storage
- Gallery Pagination by Row
- Is there a flowchart for WordPress loading sequence?
- How do register_sidebar() and get_sidebar() work together?
- Is it possible to change the attributes of a registered style or script before it fires?
- how to change “published date” format on edit.php (Posts page)?
- Querying multiple WordPress custom fields with AND qualifier
- WordPress custom post types breaks permalink on theme reinstall
- Change “logged in” link in (you must be logged in to post a comment)
- What Is The Difference Between suppress_errors() And hide_errors() in $wpdb?
- On Install, which code sets the ‘home’ option?
- How to find if a post with custom_field == X exists?
- Display a default image for custom-logo
- WP_Widget Deprecated
- Extract & Display the REAL first image attached to a post – extend the_post_thumbnail()
- Stopping People Viewing Draft Posts
- Style reset password page? /wp-login.php?action=rp
- Customizing the default logout page of WordPress
- How To Add buttons to the toolbar which appears in TinyMce when you click over images
- WordPress equivalent to Drupal Views? [closed]
- Posting as different users
- Make wordpress generate a custom XML file(not a sitemap) that is updated only when new content is posted?
- How did I enable atom feeds in a fresh WP3 install?
- Custom URL going to 404
- WordPress slugs and 404 handling takes preference over folders in site root?
- Suggestions for Implementing a Wedding Website in WordPress?
- When sale price is 0.00 show only regular price
- Save title as custom field on custom post type
- Qtranslate + Woocommerce (multiple tinymce) [closed]
- CSS Customizations for certain page
- Images give 404 after changing default domain
- Semi complicated custom taxonomy question
- Archive subtitles for different types of archives
- Point homepage to custom php page
- Display a list of subcategories (from specific Category) a post belongs to
- Implement a Walker with custom object rather than WordPress database object
- Adding tags when creating new post
- Custom Content Page
- Add Member’s birthdate from Backend and shows it on frontside [closed]
- How to add functionality to an existing theme (using child themes)
- URL and Site title outputting on Login page
- 404 when Previewing an unsaved draft
- Display a specified content on a Page and all its child pages
- Custom field not editable by the user
- WordPress category custom title
- How do I make mysite.com/comingsoon WordPress to become my main website’s WordPress?
- Use a custom page with dynamic content as a user profile page
- Invitation link to a site in multisite network does not work?
- Add helper text in custom-header section in admin
- How to edit content in code view of home page when there is some theme applied?
- WordPress core jquery version file not loaded?
- Can we add an extra button on woocommerce shop page and use it to send the product info including image in a mail?
- Add a custom intro page
- How to change custom link of subpages from of localhost to website
- How to Password Protect whole site except for some subdirectories
- Custom dropdown search form that allows users to select option B based from Option 1
- Header image doesn’t show up on page
- How to get name and email value from a custom form and add it to campaign monitor subscriber list?
- “Static” pages within a theme
- Assign classes to Custom fields
- Custom WordPress SQL Query 4 posts per custom taxonomy
- Prevent posts from being published if the ‘Uncategorized’-category or no category is selected