Skip to content
Black Friday 50% off + 15,000 credits Ends Nov 30 Ends Nov 30 see the deal
Black Friday15,000 free credits + 50% offends Nov 30

How to Edit HTML in WordPress: 6 Ways, Step by Step

WordPress lets you edit the HTML of one block, a whole page, a widget area or the theme itself, but each lives in a different place, and WordPress quietly removes some code when you save. Here is where each one is in WordPress 7.1, who can use it, and how to avoid breaking a page.

In this article
  1. 01The short answer
  2. 021. Edit one block as HTML
  3. 032. Edit a whole page in the Code editor
  4. 043. Add your own code with a Custom HTML block
  5. 05Why WordPress removes some of your code
  6. 064. Posts in the Classic editor
  7. 075. Edit your theme's HTML
  8. 086. Add code to the head of every page
  9. 09In Elementor or Divi
  10. 10Where WPOS fits
Key takeaways
  • To change one block, open its three-dot menu and choose Edit as HTML.
  • For a whole page, switch to the Code editor: Ctrl + Shift + Alt + M, or ⇧ + ⌥ + ⌘ + M on a Mac.
  • For your own markup, add a Custom HTML block; since WordPress 7.0 it has HTML, CSS and JavaScript panels.
  • Only users with unfiltered_html, normally Administrators and Editors, can save scripts and iframes.
  • Edit theme templates in the Site Editor or a child theme, not in the theme's own files.
  • Put head code such as verification tags in a header-and-footer plugin, not in a post.

The short answer

Pick the place by what you want to change:

What you want to changeWhereWho can
The markup of one blockThe block’s ⋮ menu → Edit as HTMLAnyone who can edit the post
A whole post or pageOptions ⋮ → Code editor, or Ctrl + Shift + Alt + MAnyone who can edit the post
Your own HTML, CSS or JavaScriptA Custom HTML blockScripts, CSS and JavaScript: Administrators and Editors
A post in the Classic editorThe Code tabAnyone who can edit the post
The theme’s templates and filesThe Site Editor, a child theme or the Theme File EditorAdministrators
Code in the head of every pageA header-and-footer plugin such as WPCodeAdministrators

The rest of this guide takes each one in turn, then explains why some code disappears when you save. Moving a whole static HTML site into WordPress is a different job; our guide to converting HTML to WordPress covers it.

1. Edit one block as HTML

Use this to fix a link, add an attribute or tidy the markup of a single paragraph, heading, list or image.

  1. Click the block.
  2. In the toolbar above it, open More options (the three dots, ⋮).
  3. Choose Edit as HTML. The block now shows its HTML.
  4. Make your change, then open the menu again and choose Edit visually.

Keep your change within what the block understands. WordPress’s documentation warns that “the block editor might no longer recognize the original block, depending on your code changes.” When that happens the block shows “Block contains unexpected or invalid content.” with an Attempt recovery button; its menu also offers Convert to HTML, which keeps your markup in a Custom HTML block instead.

2. Edit a whole page in the Code editor

To see or change everything at once, switch the editor to code:

  1. Open the post or page in the block editor.
  2. Click Options (⋮, top right) and, under Editor, choose Code editor. The keyboard shortcut is Ctrl + Shift + Alt + M, or ⇧ + ⌥ + ⌘ + M on a Mac.
  3. Edit the content, then click Exit code editor to go back.

You’ll see your HTML wrapped in HTML comments that start with wp:. That’s how WordPress stores blocks:

<!-- wp:paragraph -->
<p>Your text here.</p>
<!-- /wp:paragraph -->

Leave those comments alone and edit only the HTML between them. Delete or mistype one and the editor can no longer match the block, which leaves you with an invalid block or a Classic block. For a big change, copy the whole content into a text file first, so you can paste it back if something goes wrong.

3. Add your own code with a Custom HTML block

When you need markup the other blocks can’t make, such as an embed code from another service or a small table from a spreadsheet, add a Custom HTML block:

  1. Click the + inserter and choose Custom HTML, or type /html in an empty paragraph and press Enter.
  2. Click Edit HTML. A window opens with the code editor and a preview of the result beside it; it can also go full screen.
  3. Paste or type your code and click Update.

New in WordPress 7.0: the block has separate panels for HTML, CSS and JavaScript. The CSS and JavaScript panels only appear for users with the unfiltered_html capability, which the next section explains.

Why WordPress removes some of your code

If a <script> or an <iframe> vanishes when you save, WordPress removed it on purpose. Only users with the unfiltered_html capability can save any HTML they like. For everyone else WordPress cleans the content with its wp_kses() filter, which strips tags such as <script> and <iframe>.

  • On a normal site, Administrators and Editors have unfiltered_html. Authors and Contributors don’t.
  • On Multisite, only Super Admins have it, so even a site Administrator’s scripts are removed.
  • If DISALLOW_UNFILTERED_HTML is set to true in wp-config.php, nobody has it, not even Administrators. Some hosts and security setups do this on purpose.

So if your embed code keeps disappearing, ask an Administrator to add it, or use a plugin built for that kind of code (step 6). Don’t hand the capability to people you don’t trust: WordPress’s roles documentation warns that it can let them post malicious code.

4. Posts in the Classic editor

If your site uses the Classic Editor plugin, an official plugin from the WordPress team with 8,000,000+ active installs, each post has two tabs above the content: Visual and Code. The Code tab shows the post’s HTML; switch back to Visual to see the result. Older guides call it the Text tab: WordPress renamed it in version 6.8. The same capability rules apply.

5. Edit your theme's HTML

The header, the footer and the page layouts come from your theme, not from the post. Where you edit them depends on the kind of theme:

  • Block themes, such as Twenty Twenty-Five: go to Appearance → Editor and open a template or a template part. Your edits are saved in the database, so the theme’s own files stay as they were and a theme update won’t overwrite them.
  • Classic themes build their HTML in PHP files such as header.php and footer.php. Edit copies of them in a child theme, never in the theme itself: an update replaces the theme’s files, and your changes with them.

WordPress also has a built-in Theme File Editor: under Tools on block themes, under Appearance on classic themes. It edits live files with no undo, so one typo in a PHP file can take the site down. Take a backup first, or better, make the change on a staging copy. Many sites switch the editor off with define( 'DISALLOW_FILE_EDIT', true ); in wp-config.php, and on Multisite only Super Admins can use it.

Only want to change the footer text or links? Our guide to editing the footer covers every theme type.

6. Add code to the head of every page

Verification tags, analytics and other tracking codes usually belong in the page’s <head>. Don’t paste them into a post, and don’t edit header.php for them. A plugin such as WPCode (3,000,000+ active installs, updated 12 November 2026) adds code “to your WordPress site’s header and footer” and keeps it when you change themes. Developers can do the same from a child theme with the wp_head action. For SEO tags, our guide to adding meta keywords without a plugin shows both ways.

In Elementor or Divi

Page builders have their own code elements: Elementor’s HTML widget, and Divi 5’s Code module for custom HTML, CSS or JavaScript. Use them inside builder pages rather than switching those pages to the block editor’s Code editor, so the builder keeps control of its layout.

Where WPOS fits

WPOS edits at the source, in the builder your site already uses: Gutenberg, Elementor or Divi. Point at anything in the live preview inside wp-admin, pick up to five elements, say what should change, and WPOS edits the block, widget or module itself rather than pasting raw HTML on top. It checks its own render with a browser screenshot before it reports the change as done:

“In the footer, change the phone number to 020 7946 0000 and make it a link, add our Instagram next to LinkedIn, and show me a screenshot on phone and desktop.”

WPOS is our product, so weigh this section accordingly; you can try it free for 30 days with 5,000 credits, a live site plus a staging sandbox, and no card.

Frequently Asked Questions

Open the page in the block editor, click Options (the three dots at the top right) and choose Code editor, or press Ctrl + Shift + Alt + M (⇧ + ⌥ + ⌘ + M on a Mac). Edit the HTML between the block comments, then click Exit code editor. To change a single block, use its own three-dot menu and Edit as HTML.

Your account doesn't have the unfiltered_html capability, so WordPress strips tags such as script and iframe when you save. On a single site only Administrators and Editors have it, on Multisite only Super Admins, and nobody does if DISALLOW_UNFILTERED_HTML is set in wp-config.php.

The block's saved HTML no longer matches what the block expects, usually after an Edit as HTML change. Click Attempt recovery to let WordPress rebuild the block, or choose Convert to HTML from its menu to keep your markup in a Custom HTML block.

Yes. In a block theme, use Appearance → Editor, which saves your changes in the database and leaves the theme's files alone. In a classic theme, edit the PHP template files in a child theme so updates don't overwrite them. The Theme File Editor works too, but it edits live files with no undo.

Use a header-and-footer plugin such as WPCode, which keeps the code when you switch themes, or the wp_head action in a child theme. Don't paste head code into a post or a page.

Editing a block's or a page's HTML is safe: you can undo, and post revisions let you go back to an earlier version. Theme files have no undo, so take a backup first or work on a staging copy.

Black Fridayends Nov 30

Start free with 15,000 credits.

Three times the usual 5,000, no card needed. Then 50% off your site licences for 2 months with FRIDAY50.

Claim 15,000 credits