Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of letting WordPress Media Library recognize .pdf Files

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to let the WordPress media library identify .pdf files, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

How do I get the WordPress library to recognize .pdf files?

WordPress's media library (Media Library) only supports pictures, videos and audio by default. Sometimes these are not enough. The media library allows a wide variety of files to be uploaded, and more detailed categories are needed, such as pdf files.

Let the media library support pdf classification

This code from tutsplus can help us achieve the effect shown above by putting the code into the functions.php of the theme

The code is as follows

Function modify_post_mime_types ($post_mime_types) {/ / Select mime type, here use: 'application/pdf' / / then expand the array, define the text $post_mime_types [' application/pdf'] = array (_ ('PDFs'), _ (' Manage PDFs'), _ n_noop ('PDF (% s)', 'PDFs (% s)') of label) / / then we return the $post_mime_types variable return $post_mime_types;} / / Add Filter Hook add_filter ('post_mime_types',' modify_post_mime_types')

Upload a pdf file to the library and you can see the effect.

How to support more classifications

The file types supported by WordPress are written in wp_includes/functions.php. Search for them.

The code is as follows:

Function get_allowed_mime_types ()

You can find these types.

The code is as follows:

'jpg | jpeg | jpe' = >' image/jpeg', 'gif' = >' image/gif', 'png' = >' image/png', 'bmp' = >' image/bmp', 'tif | tiff' = >' image/tiff', 'ico' = >' image/x-icon', 'asf | asx | wax | wmv | wmx' = > video/asf',' avi' = > 'video/avi',' divx' = > 'video/divx',' flv' = > 'video/x-flv',.

Find the type you need and follow the

The code is as follows:

$post_mime_types ['application/pdf'] = array (_ (' PDFs'), _ ('Manage PDFs'), _ n_noop (' PDF (% s)', 'PDFs (% s)'))

Replace 'application/pdf'' with the desired mime type, and the following text should be changed accordingly. This is the way to add array members in php, and of course you can add more group elements to support multiple custom types.

The above is all the contents of the method to let the WordPress Media Library recognize .pdf files. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report