使用add_attachment
插入附件后钩住以更新段塞:
function wpse_182454_attachment_id_as_slug( $post_id ) {
if ( get_post_field( \'post_name\', $post_id ) != $post_id ) {
wp_update_post(
array(
\'ID\' => $post_id,
\'post_name\' => ( string ) $post_id,
)
);
}
}
add_action( \'add_attachment\', \'wpse_182454_attachment_id_as_slug\' );