Code in text

Highlight: Insert code-related content in monospace code font.

In text content, use monospace code font to highlight and distinguish code content from standard text. To express code font in HTMLHTML HTML is an acronym for Hyper Text Markup Language. It is a markup language that is used in the development of web pages and websites., use the <code> element. In Markdown, use backticks (`) for code font.

This page explains how to format code in standard text sentences. For more information about other code-related documentation, see Code examples, Placeholders, and Command-line syntax.

Items to put in code font

Use monospace code font while expressing the following items, which include but are not limited to:

  • Attribute names and values.
  • Class names.
  • Command-line utility names.
  • Data types.
  • Defined (constant) values for an element or attribute.
  • DNS record types.
  • Enum (enumerator) names.
  • Environment variable names.
  • Element names in XML and HTML. Place angle brackets (<>) around the element name; you may have to escape the angle brackets to make them appear in the document.
  • Filenames, filename extensions, and paths.
  • Folders and directories.
  • HTTPHTTP HTTP is an acronym for Hyper Text Transfer Protocol. HTTP is the underlying protocol used by the World Wide Web and this protocol defines how messages are formatted and transmitted, and what actions Web servers and browsers should take in response to various commands. verbs, status codes, and content-type values.
  • Language keywords.
  • Method and function names.
  • Namespace aliases.
  • Placeholder variables.
  • Query parameter names and values.
  • Text input.
  • UI elements that implement previously entered text input. For example, if the user was instructed to enter a name for a UIUI UI is an acronym for User Interface – the layout of the page the user interacts with. Think ‘how are they doing that’ and less about what they are doing. element as post-name, then when you tell them to click the element, use code font and bold: Click post-name.

For more information, see Code text preceding colon.

Items to put in regular (non-code) font

Use standard font while expressing the following items, which include but are not limited to:

  • Email addresses.
  • Names of products, services, and organizations. However, when a product name is also a command-line utility name, code font can be used.
  • URLs. For more information, see Link text.

Method names

When you refer to a method name in text, omit the class name except where including it would prevent ambiguity. Insert empty parentheses at the end of the method name to indicate that it’s a method.

Examples

Not recommended: To delete a file or directory, call the WP_Filesystem_ftpsockets::delete() method.

Recommended: To delete a file or directory, call the delete() method.

Commands

To mark a blockBlock Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. of code such as a lengthy command or a code example, use the following formatting:

  • In HTML, use the <pre> element.
  • In Markdown, use a code fence (```).

Formatting a command with multiple elements:

  • When a line exceeds 100 characters, you can safely add a line break before some characters, such as a single hyphen, double hyphen, underscore, or quotation marks. After the first line, indent each line by four spaces to vertically align each line that follows a line break.
  • If you split a command line with a line break, each line except the last line must end with the command-continuation character. Commands that don’t have the command-continuation character don’t work. Command-continuation characters are:
    • Linux or shell: A backslash preceded with a space (\)
      • Windows: A caret preceded with a space (^)
  • Use placeholder text with placeholder variables.
  • Write a descriptive list of the placeholder variables used in the command line succeeding the command line. For more information, see Describing placeholders.

Keywords

Avoid using technical keywords as verbs or nouns. If you have to, don’t change the word form of the keywords; don’t make plurals from keywords, change tense, or convert them to possessive form. It’s acceptable to use lowercase, plain text string in a general discussion of the STRING data type.

Examples

Not recommended: Decompress the encoded body.

Recommended: Decompress the encoded body by using a decompress request.

Not recommended: Retrieve information by getting the data.

Recommended: To retrieve the data, send a get request.

Not recommended: Before patch()ing, make sure your request is post()ed.

Recommended: Send a post() request before calling a patch() request.

HTTP status codes

Use the following formatting and phrasing to refer to a single HTTP status code: an HTTP 500 Internal server error status code.

Insert the HTTP status code number and name in code font. Specifically use status code rather than error code or response code. If HTTP is implied from context, it is acceptable to exclude it.

Use the following formatting to refer a range of HTTP status codes: an HTTP 2xx or 300 status code.

Insert the HTTP status code number in code font even if you’re excluding the code name. Use Nxx where N is a digit, to indicate anything in the N00 to N99 range.

Use the following formatting to specify an exact range of HTTP status codes: an HTTP status code in the 200299 range.

Insert the HTTP status code number in code font.

Coding standards

For more information about coding standards for WordPress, see Coding standards.

s
search
c
compose new post
r
reply
e
edit
t
go to top
j
go to the next post or comment
k
go to the previous post or comment
o
toggle comment visibility
esc
cancel edit post or comment