• I have a custom page created using wp_editor:

    $settings = array( 'textarea_name' => 'content', 'media_buttons' => false );
    wp_editor( '', 'content', $settings );

    I then add the content as a post:

    $post = array(
    'post_title' => sanitize_text_field($_POST['title']),
    'post_content' => wp_kses_post($_POST['content']),
    'post_status' => 'draft',
    'post_type' => 'post',
    );
    $post_id = wp_insert_post($post);

    I’ve noticed that this adds the content as a Classic block within Gutenberg. Is there a way to automatically have it converted to blocks within Gutenberg?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    If you wrap the content paragraphs in block editor delimiter comments and p tags, then the block editor should accept them as its own.

    <!-- wp:paragraph -->
    <p>Example paragraph content</p>
    <!-- /wp:paragraph -->

    The difficulty comes when content contains non-paragraph HTML where the block editor would implement a different kind of block. Your script would need to recognize this and know which block type and formatting to use for each situation. This can get quite complex, probably why the block editor simply makes everything into a classic block.

    Thread Starter wrip

    (@wrip)

    @bcworkz Thanks. I get an idea now but like you mentioned, it has a bit of an issue when the content contains different HTML tags. So I’ve decided to leave it as a classic block for now. Then I can go back and manually convert to blocks in Gutenberg editor.

    • This reply was modified 2 years, 3 months ago by wrip.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_editor() adding content as a Classic block within Gutenberg editor’ is closed to new replies.