我结合这两篇帖子的答案,自己想出了如何重新调整附件的标题:
How can I add a default description to uploaded files?
Change attachment filename
这是代码,它正在我当前的WP安装(v4.3)上运行
function wpse_retitle_attachment( $post_ID )
{
$file = get_attached_file($post_ID);
$path = pathinfo($file);
$args = array(
\'ID\' => $post_ID,
\'post_title\' => $path[\'filename\'] . "." . $path[\'extension\'],
// \'post_excerpt\' => \'My default caption ...\',
// \'post_content\' => \'My default description ...\',
);
wp_update_post( $args );
}
add_action( \'add_attachment\', \'wpse_retitle_attachment\' );