admin管理员组文章数量:1334342
In gutenberg I have several blocks:
paragraph
heading
paragraph
code
paragraph
In php I'd like to find the code
block and append content after the block.
I'd imagine I need to use add_filter
and the_content
, but I'm not sure how to go about it after that.
In gutenberg I have several blocks:
paragraph
heading
paragraph
code
paragraph
In php I'd like to find the code
block and append content after the block.
I'd imagine I need to use add_filter
and the_content
, but I'm not sure how to go about it after that.
1 Answer
Reset to default 5Yes, add_filter()
is what you're looking for, but to identify a specific block, you want the render_block
hook.
<?php
add_filter('render_block', function($block_content, $block) {
// Only for Core Code blocks
if('core/code' === $block['blockName']) {
// Add your custom HTML after the block
$block_content = $block_content . '<div>Test addition</div>';
}
// Always return the content
return $block_content;
}, 10, 2);
?>
Anywhere the code block is rendered (which would currently be the front end of a Page, Post, or CPT, but in the future could be elsewhere) your added code will appear.
本文标签: filtersAdd a div of content within thecontent after a certain block
版权声明:本文标题:filters - Add a div of content within the_content after a certain block 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742339306a2456271.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论