Command-line syntax Edit

Highlight: Follow proper command-line syntax and formatting.

This page explains how to format commands and their arguments in documentation. For more information about other code-related documentation, see Code in text, Placeholders, and Code examples.

Command prompt

When you have to show multiple lines of command-line input, initiate each line with the dollar ($) command prompt symbol.

Don’t show the current directory path before the prompt, even if part of the instruction includes creating or changing directories. This is because the directory structure might be different for the user. However, if the general context of the command-line interface changes—such as from the local machine to a remote machine—then add an additional prompt indicator for the new context.

Examples

Recommended:

<br />
$ wp theme activate twentytwentyone<br />

The output is the following:

<br />
Success: Switched to &#039;Twenty Twenty-One&#039; theme.<br />


Recommended:

<br />
$ pwd<br />
/srv/www/wordpress-develop.dev<br />
$ cat wp-cli.yml<br />
path: src/<br />

For single-line commands, the command prompt, that is the dollar symbol ($) is optional. However, if you have to show both multi-line and single-line commands, use the command prompt symbol for overall consistency.

Use separate code blocks for command-line instructions that include both input and output lines.

Example

Recommended:

<br />
$ wp cap list &#039;editor&#039; | xargs wp cap add &#039;author&#039;<br />

The output is the following:

<br />
Success: Added 24 capabilities to &#039;author&#039; role.<br />

Top ↑

Required commands and arguments

When writing commands and arguments that are required, use code font without brackets, braces, or parentheses.

Examples

Recommended:

<br />
$ wp post list &#8211;post_type=&#039;page&#039; &#8211;format=ids<br />


Recommended:

<br />
$ wp core check-update<br />


In these examples, all words and arguments are required.

For more information, see Anatomy of a command.

Top ↑

Optional arguments

When writing arguments that are optional, enclose the arguments in square brackets. If there is more than one optional argument, enclose each item in its individual set of square brackets.

Example

Recommended:

<br />
$ wp plugin install https://wordpress.org/plugins/gutenberg/ [&#8211;force] [&#8211;activate]<br />


In this example, install is required, but [--force] and [--activate] are optional arguments.

Top ↑

Mutually exclusive arguments

When writing commands where the use has to choose one item, enclose the items in angle brackets (<>; also known as inequality signs). Sometimes the mutually exclusive choices are also enclosed in braces (also known as curly braces). Use vertical bars (also knows as pipes) to separate the items. You can have more than two mutually exclusive items that are separated from each other by pipes.

Example

Recommended:

<br />
$ wp plugin install &lt;plugin|zip|url><br />


In this example, install is required, and <plugin|zip|url> is the accepted positional argument. In fact, wp plugin install accepts the same positional argument (the slug, ZIP, or URL of a plugin to install). The plugin, zip, and url choices are mutually exclusive, but one of the argument must be specified.

Top ↑

Multiple value arguments

Use an ellipsis (...) to indicate that the user can specify multiple values for the argument.

Examples

Recommended:

<br />
$ wp media import [&#8211;post_id=&lt;post_id>&#8230;]<br />


In this example, the ellipsis indicates that the user can specify multiple instances of the optional argument [--post_id=<post_id>].
Recommended:

<br />
$ wp plugin install &lt;plugin|zip|url>&#8230;<br />


In this example, the ellipsis indicates that the user can specify multiple plugins, zip files or URLs.

Top ↑

Command output

You don’t have to show an output for every command. Only add the output if it is useful; for example, if the user needs to copy a value or needs to verify a value from the output.

If you do show have to show an output, use an introductory phrase to separate the command from the output.

Examples

Recommended:

<br />
$ wp theme status twentytwentyone<br />

The output is the following:

<br />
Theme twentytwentyone details:<br />
     Name: Twenty Twenty-One<br />
     Status: Active<br />
     Version: 1.1<br />
     Author: WordPress.org<br />


Recommended:

<br />
$ wp server &#8211;host=localhost.localdomain &#8211;port=80<br />

The output is similar to the following:

<br />
PHP 5.6.9 Development Server started at Fri Jan 22 11:32:56 2021<br />
Listening on http://localhost1.localdomain1:80<br />
Document root is /<br />
Press Ctrl-C to quit.<br />

For more information about explaining placeholders in output, see Placeholders in output.

Top ↑

Additional resources

Last updated: