Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Use WordPress’s built-in Code block for a straightforward snippet: insert the block, then paste or type your code. It preserves spacing and tabs so the snippet displays as text rather than being interpreted as page content. If you want syntax colors, line numbers, a filename, or a copy button, first check which controls your WordPress editor provides; those extras vary by platform and setup.

Display a snippet with the block editor

  1. Open the post or page in the block editor.

  2. Select the plus-shaped block inserter and search for Code, or start a new line and type /code, then press Enter.

  3. Paste or type the snippet in the block. WordPress’s core documentation says the Code block preserves spacing and tabs, which helps keep indentation intact. See the WordPress.org Code block documentation and the Block Editor Handbook reference.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  4. Preview the page and check that the snippet is readable with your theme, especially on a narrow screen. Appearance can depend on the site’s theme and block implementation.

Add syntax highlighting and reader controls

The basic core Code block is for displaying code; do not assume it includes every enhancement shown in WordPress.com tutorials. WordPress.com’s documented enhanced Code block lets you select a language for syntax highlighting and offers options such as a filename, language label, copy button, line numbers, and display styles. Its support page says highlighting is available for over 120 programming languages; that is a WordPress.com feature count, not a measure of code quality or reader outcomes. See WordPress.com’s Code block guide and its announcement of the Enhanced Code block.

These controls are documented for WordPress.com. If you run a self-hosted WordPress site, or use a different WordPress.com plan or editor configuration, check the controls available in your own block settings rather than assuming they match. If language coloring or reader controls are missing, a plugin is one option. For example, the WebberZone Code Block Highlighting plugin listing describes an extension of the native core/code block, with client-side Prism.js highlighting and optional server-side highlighting with highlight.php. It also lists language, line-number, title, and highlighted-line settings. Its listing says 40 languages are included out of the box; features may change, so check the current listing and compatibility before installing.

Choose controls that serve the snippet

Use the Classic Editor for code

The Classic Editor has different formatting behavior from the block editor. WordPress.org’s Classic Editor guidance explains that inserted code can be treated as ordinary text and discusses <code>, <tt>, and <pre> markup, as well as character entities, for handling code and markup characters such as angle brackets. It also warns that quote auto-correction can affect code in the described workflow. Consult WordPress.org’s Classic Editor code guide for the relevant editing context; do not assume its steps apply unchanged to the block editor.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle long lines without making the page hard to read

When a code example has long lines, WordPress.org’s Classic Editor guide suggests showing excerpts and linking to the complete code in a text or PHP file, or using an online pastebin. That approach can keep a page easier to scan while giving readers access to the full example. Make the link text clear about what file or complete snippet it opens.

Which approach should you use?

Need Approach What to know
A short snippet with preserved indentation Core Code block Available in the block editor; WordPress documents spacing and tabs preservation.
Syntax coloring or built-in reader controls Check the editor’s Code block settings WordPress.com documents language highlighting, filename, language label, copy button, line numbers, and styles. Availability in other setups is not established by that documentation.
More highlighting or display settings on a site that lacks them Consider a compatible plugin Plugin features and compatibility can change. Review the listing and test in your own setup.
Code in the Classic Editor Follow Classic Editor-specific guidance Markup, entities, visual-editor handling, and quote correction can affect how code is displayed.
Very long lines or a complete file Show an excerpt and link to the full text or PHP file, or use a pastebin This is the approach suggested by WordPress.org’s Classic Editor guide.

The WordPress.com and plugin language counts are feature claims from their respective providers, not independent comparisons. The cited sources do not establish that one highlighting method is faster, better for SEO, or more accessible than another.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.