最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

embed - How can I display instagram block with parse_block?

programmeradmin0浏览0评论

I have a big problem. I wrote this code:

$blocks = parse_blocks( $post->post_content );

foreach ( $blocks as $block ) {
  if( $block['blockName'] != '' ) {
     $blocks_2[] .= render_block( $block );
  }
}
$num_blocks = cont($blocks_2);

for ($i = 2; $i <= $num_blocks; $i++) {
  echo $blocks_2[$i];
}

Everything is great, but it doesn't display my code blocks (instagram, twitter) in embed format, just as a url.

Can someone help me?

I have a big problem. I wrote this code:

$blocks = parse_blocks( $post->post_content );

foreach ( $blocks as $block ) {
  if( $block['blockName'] != '' ) {
     $blocks_2[] .= render_block( $block );
  }
}
$num_blocks = cont($blocks_2);

for ($i = 2; $i <= $num_blocks; $i++) {
  echo $blocks_2[$i];
}

Everything is great, but it doesn't display my code blocks (instagram, twitter) in embed format, just as a url.

Can someone help me?

Share Improve this question asked Dec 17, 2020 at 16:01 user2986284user2986284 11 bronze badge 2
  • Keep in mind this code doesn't account for nested blocks, you need to use recursion to handle that. Likewise there's a function to serialize the blocks that should be used. A foreach ( $blocks_2 as $index => $block ) { can avoid the need for the $num_blocks variable too, and there's a typo cont should be count – Tom J Nowell Commented Dec 17, 2020 at 16:35
  • Thank you very much for your suggestions! I solved the problem and it works ok. Only for simple blocks. But that's what I wanted. – user2986284 Commented Jan 5, 2021 at 17:22
Add a comment  | 

1 Answer 1

Reset to default 0

You need to apply the_content filter on the rendered blocks

发布评论

评论列表(0)

  1. 暂无评论