How do I change attachment slug from name to id
Use the add_attachment hook to update the slug after the attachment has been inserted: 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’ );