开发者

How to retrieve mime type for the current get attachment

开发者 https://www.devze.com 2023-02-28 20:51 出处:网络
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.

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


There is a function for that

echo get_post_mime_type();


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号