Retrieves the mime type of an attachment based on the ID.
Description
This function can be used with any post type, but it makes more sense with attachments.
Parameters
$post
int|WP_Postoptional- Post ID or post object. Defaults to global $post.
Default:
null
Source
*
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
* @return string|false The mime type on success, false on failure.
*/
function get_post_mime_type( $post = null ) {
$post = get_post( $post );
if ( is_object( $post ) ) {
return $post->post_mime_type;
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
Return an icon image path according to the MIME type of the given post
WordPress already has a function to get the mime type icon called wp_mime_type_icon
https://developer.wordpress.org/reference/functions/wp_mime_type_icon/