admin管理员组文章数量:1122832
I am creating some posts via the wp_insert_post()
function. When doing so the content gets saved in one big classic block. Is there anyway to force it to save as individual Paragraph blocks instead?
I am creating some posts via the wp_insert_post()
function. When doing so the content gets saved in one big classic block. Is there anyway to force it to save as individual Paragraph blocks instead?
1 Answer
Reset to default 1I ended up writing a function that wraps the <p>
tags in the block comments. This forced the content to be individual paragraph blocks in the editor. My content was only paragraphs but other block types would need to be implemented as well.
function blockify_content($content) {
//remove empty <p>
$pattern = "/<p[^>]*><\\/p[^>]*>/";
$content = preg_replace($pattern, '', $content);
//add block comments
$search = array('<p', '</p>');
$replace = array('<!-- wp:paragraph --><p', '</p><!-- /wp:paragraph -->');
$content = str_replace($search, $replace, $content);
return $content;
}
本文标签: Programmatically convert single classic block to individual blocks via PHP
版权声明:本文标题:Programmatically convert single classic block to individual blocks via PHP 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307191a1933225.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<p>
and</p>
paragraphs tags, without any attributes ? – birgire Commented May 13, 2024 at 17:44<p>
tags with classes to it. – Tony Djukic Commented May 13, 2024 at 17:47