user3157718
user3157718

Reputation: 21

How to retrieve mime type for the current get attachment

I'm uploading some pdf files and .doc/docx files in a project. So, I'm inserting a link attachment file inside the loop and is working fine.

But I need to get a specific attribute: the mimetype.

So, I need to print the attachment url and mimetype, like this

Download file on http://domain.com/wp-content/...file.pdf File Type: pdf or application/pdf

Could someone help me with this?

By the way, I´m using a custom theme and not the default wordpress theme.

Thanks a lot.

Flávio

Upvotes: 2

Views: 5217

Answers (2)

Arnaud
Arnaud

Reputation: 51

There is a function for that

echo get_post_mime_type();

Upvotes: 5

tollmanz
tollmanz

Reputation: 3223

If you are indeed dealing with an attachment post type inside the loop, you should be able to access the post_mime_type:

global $post;
$mime_type = $post->post_mime_type;

global $post may already be set, but if not, it is necessary in order to access the post data.

Upvotes: 3

Related Questions