get_post_mime_type() WordPress Function

The get_post_mime_type() function is used to get the mime type of a post. This is useful for determining the type of file that a post is, and can be used to display the correct icon for that file type.

get_post_mime_type( int|WP_Post $post = null ) #

Retrieve 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.


Top ↑

Parameters

$post

(int|WP_Post)(Optional) Post ID or post object. Defaults to global $post.

Default value: null


Top ↑

Return

(string|false) The mime type on success, false on failure.


Top ↑

Source

File: wp-includes/post.php

function get_post_mime_type( $post = null ) {
	$post = get_post( $post );

	if ( is_object( $post ) ) {
		return $post->post_mime_type;
	}

	return false;
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More