Title: Transform to code (or other block types)
Last modified: November 28, 2018

---

# Transform to code (or other block types)

 *  [Tim Trott](https://wordpress.org/support/users/azuliadesigns/)
 * (@azuliadesigns)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/transform-to-code-or-other-block-types/)
 * Hi,
 * I’m working on migrating a custom CMS to WordPress and giving Gutenburg a spin.
   So far it’s ok, but I’m having problems with the “Convert To Blocks” and “Transform
   To” function.
 * I have a post imported (via custom logic using wp_insert_post). Within the post
   there are pre tags containing sourcecode. I would like these to be converted 
   to code blocks when using “Convert To Blocks”.
 * I can change what the pre tags are if there is one that is automatically gets
   converted to code. code does not convert either, pre has better formatting so
   I used that.
 * Failing that, I can use the “Transform to” option, but I can only go from paragraph
   to preformatted and back. How do I transform a paragraph or preformatted block
   to a code block? I can add a new block and copy & paste the code, but that isn’t
   realistic for 600+ pages with upto 8 sourcecode snippets.
 * Development version (5.0-RC1-43945).
 * Thanks
    -  This topic was modified 7 years, 6 months ago by [Tim Trott](https://wordpress.org/support/users/azuliadesigns/).
    -  This topic was modified 7 years, 6 months ago by [Tim Trott](https://wordpress.org/support/users/azuliadesigns/).

Viewing 1 replies (of 1 total)

 *  Thread Starter [Tim Trott](https://wordpress.org/support/users/azuliadesigns/)
 * (@azuliadesigns)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/transform-to-code-or-other-block-types/#post-10944801)
 * Is there alternatively a way to call “Convert to Blocks” from PHP?
 * I want to import 2,400 posts via wp_insert_post, then convert to block as they
   are inserted, then I will do some string manipulation on the post_content field
   via SQL (changing preformatted to code), then I can go through individual posts
   and tidy up one by one.
 * Something like wp_convert_to_blocks($postId) would be ideal.
 * Thanks

Viewing 1 replies (of 1 total)

The topic ‘Transform to code (or other block types)’ is closed to new replies.

 * ![](https://ps.w.org/gutenberg/assets/icon-256x256.jpg?rev=1776042)
 * [Gutenberg](https://wordpress.org/plugins/gutenberg/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gutenberg/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gutenberg/)
 * [Active Topics](https://wordpress.org/support/plugin/gutenberg/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gutenberg/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gutenberg/reviews/)

## Tags

 * [block](https://wordpress.org/support/topic-tag/block/)
 * [code](https://wordpress.org/support/topic-tag/code/)
 * [Gutenburg](https://wordpress.org/support/topic-tag/gutenburg/)

 * 1 reply
 * 1 participant
 * Last reply from: [Tim Trott](https://wordpress.org/support/users/azuliadesigns/)
 * Last activity: [7 years, 6 months ago](https://wordpress.org/support/topic/transform-to-code-or-other-block-types/#post-10944801)
 * Status: not resolved