get_post_mime_type

Retrieve the mime type of an attachment based on the ID.

Description

(string|false) get_post_mime_type( (string) $ID = '' ); 

This function can be used with any post type, but it makes more sense with attachments.

Returns (string|false)

The mime type on success, false on failure.

Parameters (1)

0. $id — Optional. (string)
Post ID or post object. Default empty.

Usage

  1. if ( !function_exists( 'get_post_mime_type' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Optional. Post ID or post object. Default empty. 
  5. $id = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_post_mime_type($id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function get_post_mime_type( $ID = '' ) { 
  2. $post = get_post($ID); 
  3.  
  4. if ( is_object($post) ) 
  5. return $post->post_mime_type; 
  6.  
  7. return false;