admin管理员组文章数量:1122846
When using insert media into a page it shows a grid of pictures. How can I change that to see file names instead (or both)? And would there be a way to have the images sort by file name?
When using insert media into a page it shows a grid of pictures. How can I change that to see file names instead (or both)? And would there be a way to have the images sort by file name?
Share Improve this question asked May 10, 2024 at 21:25 CAlexanderCAlexander 11 Answer
Reset to default 1By default, WordPress doesn't provide a built-in option to sort media attachments by file name in the media library interface. However, you can achieve this programmatically or with the help of plugins.
Using Plugins: Plugins like "Media Library Assistant" or "Media Library Categories" offer advanced sorting and filtering options for the media library, including sorting by file name.
Custom Code: If you prefer custom development, you can use WordPress hooks and filters to modify the query parameters for retrieving media attachments and sort them by file name.
Here's a basic example:
function custom_media_library_sort_by_filename($query) {
if (is_admin() && $query->is_main_query() && $query->get('post_type') == 'attachment') {
$query->set('orderby', 'title');
$query->set('order', 'ASC'); // or 'DESC' for descending order
}
}
add_action('pre_get_posts', 'custom_media_library_sort_by_filename');
This code snippet hooks into the pre_get_posts action to modify the query parameters for retrieving media attachments. It sets the orderby parameter to 'title' (which represents the file name) and specifies the sorting order.
Whether you choose to use a plugin or custom code depends on your preferences and the specific requirements of your website. Plugins offer convenience and often come with additional features, while custom code provides more flexibility and control over the implementation.
本文标签: When inserting media file in a post or pageshow file name under the thumbnail
版权声明:本文标题:When inserting media file in a post or page, show file name under the thumbnail 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307476a1933325.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论