• Resolved odoremieux

    (@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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter odoremieux

    (@odoremieux)

    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
    
    */
    
    }
    
    }
    Plugin Support Herman Asrori (BSF)

    (@bsfherman)

    Hi @odoremieux,

    If you think your code will make this plugin better, please raise PR in our GitHub. Our team will take a look and verify it.

    Thanks for your support and effort.

    Kind regards,
    Herman ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘<scrip id="cst_font_data" … added twice’ is closed to new replies.