Skip to content

WP-CLI Command: convertΒ #187

@flexseth

Description

@flexseth

Description

The convert command for WP-CLI changes data from one type to another.

Sample use case: Markdown to Block Markup

The idea is to be able to consume a Markdown file and turn it into a HTML file, which could then be copy/pasted or otherwise imported via the CLI into the Block Editor.

Given the following best-chicken-wings-in-scotland.md file

## Scotland's Best Chicken Wings
Found in Edinburgh, you have to visit the Wingstop at Edinburgh Fountain Stop.

These are the best wings you will find around!

![An image of a crispy chicken wing being dunked into ranch dressing](https://github.com/wp-cli/ideas/assets/3792502/a0c5ee69-d2a3-4158-bedf-a31f18529089)

Converts to

<!-- wp:heading -->
<h2 class="wp-block-heading">Scotland's Best Chicken Wings</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Found in Edinburgh, you have to visit the Wingstop at Edinburgh Fountain Stop.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>These are the best wings you will find around!</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":7,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="http://development.local/wp-content/uploads/2024/06/chicken-wing.jpg" alt="An image of a crispy chicken wing being dunked into ranch dressing" class="wp-image-7"/></figure>
<!-- /wp:image -->

Syntax

wp post convert best-chicken-wings-in-scotland.md

Success: Converted to HTML.


Flags

--create β€” Create the post as a draft in this WordPress instance.
--copy β€” Copy HTML to the clipboard.
--no-follow β€” Add no-follow to any image tags (good for adverts)

Behind the scenes

Uploads any images found into the Media Gallery

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions