If you change a bit your code
With this code, it’s added only once, and in the head. Your current code add it before the html tag
<style type="text/css" id="cst_font_data"> @font-face { font-family: 'Gotham Bold'; font-weight: 400; src: url('https://gutenberg.local/wp-content/uploads/2023/10/Gotham-Bold.otf') format('OpenType'); } </style> <!DOCTYPE html> <html class="wp-toolbar" lang="en-US"> <head>
Here are some suggestions
public function add_block_assets_style() {
if ( is_admin() && ! is_customize_preview() ) {
wp_register_style( 'cst_font_data', false );
wp_enqueue_style( 'cst_font_data' );
add_action( 'enqueue_block_assets', array( $this, 'add_style' ) );
}
add_action( 'enqueue_block_editor_assets', array( $this, 'enque_data' ) );
}
public function add_style() {
$font_styles = '';
$query_posts = $this->get_existing_font_posts();
if ( $query_posts ) {
foreach ( $query_posts as $key => $post_id ) {
$font_styles .= get_post_meta( $post_id, 'fonts-face', true );
}
wp_reset_postdata();
}
if ( ! empty( $font_styles ) ) {
wp_add_inline_style('cst_font_data',wp_strip_all_tags( $font_styles ));
/*
?>
<style type="text/css" id="cst_font_data">
<?php echo wp_strip_all_tags( $font_styles ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</style>
<?php
*/
}
}