Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
odoremieux opened this issue Oct 20, 2023 · 0 comments
Open

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

odoremieux opened this issue Oct 20, 2023 · 0 comments

Comments

@odoremieux
Copy link

odoremieux commented Oct 20, 2023

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant