diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php
index 3f912ad061..c9bbc1bb55 100644
--- a/src/wp-includes/block-template-utils.php
+++ b/src/wp-includes/block-template-utils.php
@@ -1309,7 +1309,7 @@ function wp_generate_block_templates_export_file() {
 	$theme_json_raw = $tree->get_data();
 	// If a version is defined, add a schema.
 	if ( $theme_json_raw['version'] ) {
-		$theme_json_version = 'wp/' . substr( $wp_version, 0, 3 );
+		$theme_json_version = 'wp/' . substr( $version, 0, strpos( $version, '-' ) );
 		$schema             = array( '$schema' => 'https://schemas.wp.org/' . $theme_json_version . '/theme.json' );
 		$theme_json_raw     = array_merge( $schema, $theme_json_raw );
 	}
