将 WordPress Gallery 短代码 slug 更改为文件名
是否可以将附件页面别名更改为引用文件名?简而言之...我使用 图库简码 构建一个简单的基于页面的图库。
我在上传过程中更改了原始文件名(如 DSC1223.jpg)(更改为 3b1871561aab.jpg),但它不会在 url 中显示为 slug。它仅使用 DSC1223。
有什么办法可以改变吗?
问候,史蒂夫
最好的方法是在我的functions.php中写这样的东西
function twentyten_filter_wp_handle_upload () {
$upload = wp_handle_upload();
}
add_filter( 'wp_handle_upload', 'twentyten_filter_wp_handle_upload', 10, 2);
Is it possible to change the attachment page slug to the referring filename? In short... i use the Gallery Shortcode to build a simple page based gallery.
I change the orignal filename (like DSC1223.jpg) during the upload process (to 3b1871561aab.jpg) but it does not appery as slug within the url. It uses only DSC1223.
Is there anyway to change ist?
Regards, Steve
The best way would be to write something like this in my functions.php
function twentyten_filter_wp_handle_upload () {
$upload = wp_handle_upload();
}
add_filter( 'wp_handle_upload', 'twentyten_filter_wp_handle_upload', 10, 2);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其添加到哈希上传文件名插件,你应该可以开始了;
如果您不确定每行的作用,请随时询问!
更新:
在将新附件保存到数据库后,此函数会挂钩
add_attachment
事件。此操作是从wp_insert_attachment()
内部调用的。我们首先获取附件的文件名 (
get_attached_file()
)。然后我们使用原生 PHP 函数 pathinfo() 获取路径组件,并去掉目录路径和文件扩展名。然后我们调用
wp_update_post()
,更新数据库中附件的post_name
。Add this to the hash upload filename plugin and you should be good to go;
Don't hesitate to ask if you're not sure what each line does!
UPDATE:
This function hooks onto the
add_attachment
event, just after a new attachment is saved to the database. This action is called from withinwp_insert_attachment()
.We first grab the filename of the attachment (
get_attached_file()
). Then we use a native PHP function pathinfo() to get the path components, and strip the directory path and file extension away.Then we call
wp_update_post()
, updating thepost_name
of the attachment in the database.