• Resolved Amibe Websites

    (@amibe)


    Hi, thank you for this plugin.

    I’m pulling in content using WP_Query and a “while ( have_posts() ) : the_post()” loop, using the_content() to output the post.

    The CSS isn’t included – what can I add to this to make sure the CSS is also outputted with each post?

Viewing 1 replies (of 1 total)
  • Plugin Author Hardeep Asrani

    (@hardeepasrani)

    Hey @amibe,

    Inside your query, you can do something like this:

    $css = new \ThemeIsle\GutenbergBlocks\Blocks_CSS();
    
    $blocks = $css->parse_blocks( get_the_content() );
    
    if ( ! is_array( $blocks ) || empty( $blocks ) ) {
    	return;
    }
    
    $css = $css->cycle_through_blocks( $blocks, get_the_ID() );
    
    if ( empty( $css ) ) {
    	return;
    }
    
    $style  = "\n" . '<style type="text/css" media="all">' . "\n";
    $style .= $css;
    $style .= "\n" . '</style>' . "\n";
    
    echo $style;

    Let me know if that works!

Viewing 1 replies (of 1 total)
  • The topic ‘CSS missing when using the_content()’ is closed to new replies.