admin管理员组

文章数量:1122846

i am trying to render one of my custom blocks inside a PHP file:

<?php
    $block_content = do_blocks( '
        <!-- wp:create-block/gb-button-block  /-->'
    );

    echo $block_content; 
    ?>

The result, it doesnt display the button:

Now if i try it with an official wordpress block:


<?php
    $block_content = '<!-- wp:latest-posts {"postsToShow":3,"displayPostContent":true,"excerptLength":30,"displayPostDate":true,"postLayout":"grid","displayFeaturedImage":true,"featuredImageSizeSlug":"large","align":"wide","className":"tw-mt-8 tw-img-ratio-3-2 tw-stretched-link is-style-default"} /-->';
    
    echo do_blocks($block_content);
    ?>

It works perfectly:

Idk if im doing something wrong, the button block works perfectly outside of this PHP example.

Thank you!

i am trying to render one of my custom blocks inside a PHP file:

<?php
    $block_content = do_blocks( '
        <!-- wp:create-block/gb-button-block  /-->'
    );

    echo $block_content; 
    ?>

The result, it doesnt display the button:

Now if i try it with an official wordpress block:


<?php
    $block_content = '<!-- wp:latest-posts {"postsToShow":3,"displayPostContent":true,"excerptLength":30,"displayPostDate":true,"postLayout":"grid","displayFeaturedImage":true,"featuredImageSizeSlug":"large","align":"wide","className":"tw-mt-8 tw-img-ratio-3-2 tw-stretched-link is-style-default"} /-->';
    
    echo do_blocks($block_content);
    ?>

It works perfectly:

Idk if im doing something wrong, the button block works perfectly outside of this PHP example.

Thank you!

Share Improve this question edited Dec 5, 2023 at 9:09 JPD asked Dec 5, 2023 at 8:16 JPDJPD 133 bronze badges 2
  • How does your block work? Is it a dynamic block rendered on the server? Or is the block data saved as HTML? In the editor, add your block, then copy the block and paste it into a text editor. Whatever is pasted is what you need to pass to do_blocks(). – Jacob Peattie Commented Dec 5, 2023 at 9:24
  • It is a Static block, i did as you said and it worked perfectly!. – JPD Commented Dec 5, 2023 at 13:17
Add a comment  | 

1 Answer 1

Reset to default 0

It could be that the block is processing CSS, and that CSS processing has already occured. You need to thus run the do block in the header, or that is the solution I've been told. I've not gotten it to work, for myself.

本文标签: phpdoblocks not working with a custom block