Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I insert a block code inside a php page? [closed]

I have this front-page.php page in my site and I want to put a block code directly in the php page. So I got a div and I want to put it in there. But the code is like

<!-- 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"} /-->

It's from a widget. I coudn't make it work please help :D

like image 546
lucazdj Avatar asked Sep 01 '25 20:09

lucazdj


1 Answers

You can insert block code into any php template by using the function do_blocks() and passing in (valid) block content as a string, eg:

    <?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);

    ?>
like image 179
S.Walsh Avatar answered Sep 03 '25 12:09

S.Walsh