• Resolved marios88

    (@partakaw)


    Hello, when using ‘do_blocks’ the relevant CSS is not injected.

    example code in functions.php

    function append2content( $content ) {
             return $content .  do_blocks( '<!-- wp:block {"ref":2168} /-->' );
    }
    add_filter( 'the_content', 'append2content' );

    Is it possible to get the CSS in order for it to render correctly?

Viewing 1 replies (of 1 total)
  • Thread Starter marios88

    (@partakaw)

    This was harder than expected.

    First create your block as a reusable block, then include it like this in your functions.php

    To find the id you want to load the assets from, use a plugin that enables you to edit reusable blocks.

    Also, you dont have to use enqueue_scripts() in head, it will work in the content, if you display the block conditionally

    add_action ( 'astra_html_before', static function() {
        //polylang get current language code
        $lang = pll_current_language();
        match ($lang) {
            'el' => $loadAssetsFromId = 2005,
            'en' => $loadAssetsFromId = 2006,
        };
        (new UAGB_Post_Assets( $loadAssetsFromId ))->enqueue_scripts();
    },10,0);
    
    add_filter( 'astra_content_after', static function( $content ) {
        echo $content.do_blocks( '<!-- wp:block {"ref":2005} /-->' );
    },10,1);
Viewing 1 replies (of 1 total)

The topic ‘do_blocks missing CSS’ is closed to new replies.