• Resolved xoex

    (@xoex)


    Thanks for the plugin, it’s very useful.
    But There’s a problem with the main page, I’m using Astra theme (I have the same problem with another older theme). I’m using full content in the main page with read more button (not excerpt).
    All styles that are applied to blocks are working in single pages, but styles are missing in the main page (and category and tag pages too).
    It also doesn’t work in search pages if there are more than one result.
    Could you fix this bug?

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

    (@xoex)

    I propose this way of enqueuing styles.

    public function render_server_side_css() {
    		if ( function_exists( 'has_blocks' ) && has_blocks( get_the_ID() ) ) {
    			//global $post;
    			global $wp_query;
    			$posts = $wp_query->get_posts();
    
    			if (!is_array($posts))
    			{
    				return;
    			}
    			
    			$styles = '';
    
    			foreach ($posts as $post)
    			{
    				if ( ! is_object( $post ) ) {
    					continue;
    				}
    
    				$blocks = parse_blocks( $post->post_content );
    
    				if ( ! is_array( $blocks ) || empty( $blocks ) ) {
    					continue;
    				}
    
    				$css = $this->cycle_through_blocks( $blocks, $post->ID );
    
    				if ( !empty( $css ) ) {
    					$styles .= $css;
    				}
    			}
    
    			if (empty($styles))
    			{
    				return;
    			}
    
    			$style  = "\n" . '<style type="text/css" media="all">' . "\n";
    			$style .= $styles;
    			$style .= "\n" . '</style>' . "\n";
    
    			echo $style; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    		}
    	}
    • This reply was modified 1 year, 12 months ago by xoex.
    Plugin Author Hardeep Asrani

    (@hardeepasrani)

    Hey @xoex,

    Thank you for the report and snippet. We will check and add it to an upcoming version in a couple of weeks.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Styles are missing in main page’ is closed to new replies.