Originally published: July 31, 2021 · Last updated: August 13, 2026
WordPress lets you work visually most of the time, but there are situations where editing HTML directly is the cleanest option: adding a small embed, correcting markup, inspecting a block, or inserting code that does not have a dedicated block.
The important distinction is between editing content HTML and editing theme or plugin files. The first is usually low-risk. The second can break the site and should be handled with proper development tools and backups.
Edit a single block as HTML
In the block editor, select a block, open its three-dot menu and choose Edit as HTML. WordPress shows the markup generated by that block. This is useful for small changes when you understand the block’s expected structure.
Be conservative. If you substantially change markup that a block expects to control, WordPress may report that the block contains unexpected or invalid content. If that happens, you can often recover the block or convert it to Custom HTML.
Use the Custom HTML block
For standalone markup, the Custom HTML block is usually cleaner than modifying a normal paragraph or heading block. Type /html in the editor to insert one quickly.
WordPress 7.0 expanded the Custom HTML experience with dedicated editing panels. Depending on your user capability, WordPress can sanitize unsafe markup when the post is saved. Users without the unfiltered_html capability may see elements such as scripts or iframes removed.
Edit the whole post in Code Editor
The block editor also includes a Code Editor mode for the entire post. Open the editor’s main options menu and switch from Visual editor to Code editor. This exposes the block comments and HTML used to store the complete post.
This mode is valuable for troubleshooting, but it is easier to damage block structure because you are editing everything at once. Make one change at a time and keep a revision you can restore.
Classic Editor sites
If a site still uses the Classic Editor, the Text tab exposes the article’s HTML. This remains useful for legacy sites, but new WordPress installations are centered on the block editor.
Do not edit theme files just to add content HTML
Changing functions.php, template PHP files or plugin files is a different task. Theme updates can overwrite modifications, a syntax error can produce a fatal error, and copied snippets can introduce security problems.
If you need site-wide code, use the appropriate mechanism: a child theme, a site-specific plugin, a code-snippet manager, a theme builder or a hook provided by your theme. Test changes on staging when they affect templates or PHP.
HTML safety checklist
- Prefer native WordPress blocks when they already solve the problem.
- Use Custom HTML for isolated markup.
- Give embedded content meaningful accessibility labels where appropriate.
- Never paste unknown JavaScript or tracking code simply because a tutorial says to.
- Preview the page on desktop and mobile after changing markup.
- If a block becomes invalid, use WordPress recovery options before deleting it.
- Keep backups before editing theme or plugin files.
When HTML is the wrong tool
If you are repeatedly adding the same structure by hand, create a pattern, shortcode, block, template or custom field instead. Manual HTML is excellent for one-off adjustments; it becomes technical debt when it is used as a substitute for a maintainable content model.
Official references: Custom HTML block and Edit as HTML.