这将在编辑附件页面中添加一个slug字段,允许您在选择的时间和方式进行独立更改。
将其放入插件或主题functions.php
;
function wpse_12405_edit_attachment_name( $fields, $post ) {
$fields[\'post_name\'] = array(
\'label\' => __( \'Slug\' ),
\'value\' => $post->post_name,
);
return $fields;
}
add_filter( \'attachment_fields_to_edit\', \'wpse_12405_edit_attachment_name\', 10, 2 );
function wpse_12405_save_attachment_name( $attachment, $POST_data ) {
if ( ! empty( $POST_data[\'post_name\'] ) )
$attachment[\'post_name\'] = $POST_data[\'post_name\'];
return $attachment;
}
add_filter( \'attachment_fields_to_save\', \'wpse_12405_save_attachment_name\', 10, 2);