WP-CLI markdown post is a custom WP-CLI command tool which allows you to publish and update posts with markdown files in a terminal.
How to use it?
Let’s see how to create a markdown file and publish it to your website.
Create a markdown file
Login to the machine which your website is running on.
# Create a markdown file with name "useful-git-commands"
# You do need to write the extension ".md", the tool does it for you.
$ wp new wp-cli-markdown-post
Success: wp-cli-markdown-post.md is created!
The new created wp-cli-markdown-post.md
looks like below:
---
post_title:
post_name:
post_author:
post_type: post
post_status: publish
tags_input:
-
post_category:
-
description:
---
It contains a YAML part (wrapped by ---
and ---
) to allow you to set some meta fields and the post content which follows the YAML.
This a full example of a post written with markdown.
---
post_title: WP-CLI markdown post tool
post_author: 108
post_type: post
post_status: publish
tags_input:
- wp-cli
post_category:
- wordpress
description: "WP-CLI markdown post is a custom WP-CLI command tool which allows you to publish and update posts with markdown files in a terminal."
---
[WP-CLI markdown post](https://github.com/gloomic/wp-cli-markdown-post) is a custom WP-CLI command tool which allows you to publish and update posts with markdown files in a terminal.
The second paragraph ...
Publish a post with a markdown file
To publish the markdown file created previously:
$ wp create wp-cli-markdown-post.md
Success: 920
This command will publish the post to the website and update the file by adding an ID
in the YAML part:
---
ID: 920
post_title: WP-CLI markdown post tool
Update a post with a markdown file
To update a post with a markdown file which has been published before:
# Update useful-git-commands.md and save it.
# Update to website.
$ wp update useful-git-commands.md
Installing
Prerequisites
To use it you need first install the official WP-CLI tool provided by wordpress.org. It is a compressed package, just download it, put it somewhere on the path and make it executable.
On Linux:
# Download wp-cli
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
# Make it executable.
$ chmod +x wp-cli.phar
# Rename it for less typing and move it somewhere in your path.
$ sudo mv wp-cli.phar /usr/local/bin/wp
It is similar on Windows.
See Installing WP-CLI for more details.
Install WP-CLI markdown post tool
Copy wp-cli-markdown-post-command.php
to your current using theme and include it in the functions.php
file on the server. Take care to use different code depending on you are using a normal theme or a child one (name ends with -child
).
If you are using a normal theme:
// Use below code if you are using a parent theme.
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once( get_parent_theme_file_path() . '/wp-cli-markdown-post-command.php' );
}
Or if you are using a child theme:
// Use below code if you are using a child theme.
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once( get_stylesheet_directory() . '/wp-cli-markdown-post-command.php' );
}
Read more
- WP-CLI markdown post tool GitHub repository
-
WordPress Git post tool GitHub repository
A tool that allows you to publish or update posts to a remote WordPress site with Git commands.
-
Running WP-CLI remotely over SSH.
How to config SSH to run WP-CLI from remote server via a client. Below are some command examples:
# @svf is the remote server which has been configured. $ wp @svr info OS: xxx Shell: xxx PHP binary: xxx PHP version: xxx ... WP-CLI version: x.x.x $ wp @svr post get --field=post_name post_name running-wp-cli-remotely-over-ssh