I 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;
}
Related Posts:
- How to serialize a Gutenberg block from block attributes in PHP?
- Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?
- is_admin returning false in backend in server side rendered block
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- add_meta_boxes action with refresh on save
- Gutenberg custom block using only register_block_type() and HTML
- Include a Gutenberg Block in a PHP file
- Create custom blocks for bootstrap
- How to return output of the new wp gallery block for automatically Link images To Media file
- Register JS for block on frontend only
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- How to programmatically add Gallery Block to Existing Post Content
- Best way to add more options to Gutenberg “More Rich” text controls drop down
- Fetch post block/field data as JSON with WordPress API
- Gutenberg block – Save PHP function’s output as HTML?
- Where to find documentation for CPT block template? (PHP)
- Generate YouTube image thumbnail in a Gutenberg block – ACF + Timber
- Add class to group inner container
- Multiple requests external data api dynamic block gutenberg
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- parsing nested blocks (in columns, etc) via PHP
- Passing the name of selected color from the custom component to `render_callback`
- InnerBlocks with allowedBlocks not working with acf_register_block
- Guttenburg and Classic Editor – How to use the custom guttenburg block in classic editor?
- How to render a block from php template
- Want to unrestrict plugin block
- WordPress – Get Posts with Category data
- Additional file upload in Gutenberg page options/featured image
- Add Block Before Entry Title Using PHP
- How to populate a Gutenberg select field SelectControl with option value from PHP array
- Gutenberg Blocks and get_option() for styling
- How to extend SelectControl with data from my theme
- Copying and pasting to WordPress “code editor” code via the front end and clipboard
- Gutenberg block don’t save rich text content
- Is there a PHP function that will return the block ID generated by WordPress?
- register_block_type is not working properly
- Categories does not show Block editor WordPress
- Block that renders html saved in a php file
- Show Gutenberg facebook embed with a custom theme
- Gutenberg – render_callback does not pass ToggleControl value on frontend
- Add default block css when the block has been added with php?
- Custom Post Type doesn’t have template content when creating programmatically in PHP but does when created in WP Admin
- How to add different menu items on different menus?
- How to enable REST API on custom post type without Gutenberg?
- Replace block content with an array
- Include a static block inside of a dynamic block
- WordPress Block Editor Gutenberg running code inside ! is_admin()
- Manipulating the allowed inner blocks of a core-gutenberg-block?
- Adding features to Gutenberg without theme.json
- Registering a custom block style
- Get column block count using PHP method render_block
- do_blocks not working with a custom block
- ACF block gutenberg aligncenter don’t work
- Execute a PHP Function when a Block is used and access it’s attributes
- How to edit templates created in the block editor in code / template files not updating
- How to add elements to an empty array in PHP?
- Decrease file size upload in Media
- WP E-commerce: Showing 3 random products from current category when viewing product
- If Custom Field is empty don’t display div
- the_author_posts_link css class
- error_log is not working as expected in functions.php file
- WordPress template_include filter not working properly
- Web scraping using transients
- doing an ajax request always outputs 0
- What is the intended purpose of the _wp_attachment_context post meta key?
- PHP Script for last login time
- Why the JavaScript code is ignored from wp editor?
- Send an email to specific adress when button is clicked?
- PHP version problem?
- Why Won’t My Inputs in a form with a Get method work together?
- Automatic Shortcode Creation with Custom Fields [closed]
- WordPress function when file is uploaded, deleted or edited
- Using a $GET parameter from a URL, to redirect to a URL (WordPress)
- User Meta Value not echoing despite Var_Dump Showing correct string
- Why does my user not get added to the database on custom registration?
- WordPress check if current taxonomy has child
- get_theme_mod outputs number when using WP_Customize_Cropped_Image_Control
- array_rand not working correctly?
- How do I increase the upload size only when editing special pages?
- Show login greeting above sub-menu links?
- Conditional On custom field plugin metabox
- Exclude function from running on a certain page
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- How to change image product page by variation in PHP code?
- Fetch Data from an external MSSQL Database in a Managed WP hosting
- How can I show how much water got saved on this order (making use of the number of items bought) on a thank-you-page?
- How to add WordPress Featured image in tag ..?
- Unable to update plug-ins – Undefined index a:1:{s:3:”ssl”;b:1;} in class-requests.php on line 213
- Php cron job (wp-cron) not working
- Make sticky post with FacetWP
- Get meta_query value by user meta array
- Can we use corePHP code in wordpress?
- how can I disallow special characters, space, capital letter, dot in user name on registration?
- Rewrite /keyword1+keyword2.html to search page | .htaccess
- Insert double entry in DB
- WordPress display name string manipulation
- Having an HTTP error 500 after migrating a website
- Saving User Input to PHP Variable
- Deprecated: Return type of WC_Appointments_Availability::offsetExists($offset) [closed]
- Sort Woocommerce Products with Numbered Titles Numerically