Skip to content

<scrip id="cst_font_data" … added twice #106

@odoremieux

Description

@odoremieux

The part with <style type=”text/css” id=”cst_font_data”> is added twice when I go to edit a page.

I did test it on a simple site, with the default theme and just that plugin.

And it output one time before :
Like that:

<style type="text/css" id="cst_font_data"> @font-face { font-family: 'Gotham Bold'; font-weight: 400; src: url('http://gutenberg.local/wp-content/uploads/2023/10/Gotham-Bold.otf') format('OpenType'); } </style>

Here is some suggested code to help :
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"> </style>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions