How to Edit HTML in WordPress
Safe ways to customize your WordPress code without breaking your site
Sometimes the only way to get your WordPress site looking exactly how you want is to edit the underlying HTML. Maybe you need to tweak a button, embed a custom form, or fix a broken layout. The problem: if you edit the wrong thing in the wrong place, you can easily break your page or theme.
In this tutorial, you’ll learn the safest ways to edit HTML in WordPress: inside the block (Gutenberg) editor, using the Classic Editor, via widgets and Custom HTML blocks, and in theme template files. We’ll walk through each option step by step so you know where to click, what to edit, and how to undo mistakes if something goes wrong.
If you’re just starting out with content changes in general, you can pair this tutorial with a broader walkthrough on how to edit a WordPress site, then come back here whenever you need to work directly with the HTML.
Prerequisites
Before you edit any HTML, make sure you can safely recover your site if something breaks. Even small typos in HTML or PHP can cause layout issues or white screens.
- Admin access to your WordPress dashboard (username and password).
- Basic familiarity with HTML tags like
<div>,<p>,<a>, and<span>. - A recent full backup of your WordPress site (files and database).
- Optional but recommended: a staging site where you can test edits before going live.
Not sure how to handle backups? Follow the beginner guide to WordPress backup and restore strategies first, then return to this tutorial.
Step 1: Decide Where You Need to Edit HTML
“Editing HTML in WordPress” can mean a few different things, depending on what you’re trying to change. Start by deciding where the HTML you want to change actually lives.
- Post or page content: Text, headings, images, buttons, and embeds inside a single page or post. This is usually edited via the block (Gutenberg) editor or Classic Editor.
- Sidebar, footer, or header widgets: Items in widget areas like sidebars, footers, and sometimes header bars. These often use widgets or Custom HTML blocks.
- Theme templates: Structural HTML for your header, footer, single posts, archives, and other layouts. These live in your theme’s PHP files (for example,
header.php,single.php,footer.php).
If you’re using a magazine theme like Jannah, some of what feels like “HTML editing” can be done through its Theme Options and built-in layout controls rather than editing template files directly. Always check the theme’s options panel first—there may be a safer setting-based way to achieve the same result.
Step 2: Edit HTML in the Block (Gutenberg) Editor
If your site uses the modern block editor (Gutenberg), you can edit HTML either for the whole document or for individual blocks. This is the safest way to adjust HTML for most posts and pages.
2.1 Open your page or post
- Log in to your WordPress dashboard.
- Go to Pages → All Pages or Posts → All Posts.
- Hover over the page/post you want to edit and click Edit.
2.2 Edit HTML for a specific block
- Click the block you want to modify (for example, a Paragraph or Button block).
- Click the three-dot menu (More options) in the block toolbar.
- Choose Edit as HTML.
You’ll now see the HTML for that single block. You might see something like this:
<p>Welcome to our <strong>WordPress site</strong>!</p>
You can safely tweak tags here, for example:
<p class="intro">Welcome to our <strong>WordPress site</strong>!</p>
When you’re done, click the three-dot menu again and choose Edit visually to return to the normal view.
2.3 Edit the entire page as HTML (code editor)
- In the top-right corner of the editor, click the three-dot menu (Options).
- Under Editor, choose Code editor.
- The entire page content will switch to a mix of HTML and block markup (for example,
<!-- wp:paragraph -->comments).
<!-- wp:... --> comments unless you know what they do. These comments tell WordPress which blocks you’re using. Make your HTML changes, then click the three-dot menu again and choose Visual editor. Use the Preview button to confirm everything still looks correct before clicking Update.
Step 3: Edit HTML Using the Classic Editor
If your site still uses the Classic Editor (or the Classic Editor plugin), you can switch between a visual view and a raw HTML view using the Visual/Text tabs.
3.1 Open the Classic Editor
- From the dashboard, go to Pages → All Pages or Posts → All Posts.
- Click Edit on the page or post you want to modify.
- If you see familiar Visual/Text tabs instead of blocks, you’re using the Classic Editor.
3.2 Switch to the Text (HTML) tab
- In the editor, click the Text tab at the top right of the content box.
- Your content will now appear as HTML. For example:
<h2>About Our Agency</h2>
<p>We build fast, secure WordPress websites for growing businesses.</p>
You can edit this HTML directly—add classes, wrap text in extra tags, or paste safe embed codes. When you’re finished, click the Visual tab again to see how it looks.
Step 4: Edit HTML in Widgets and Custom HTML Blocks
Many sites use widgets or dedicated HTML blocks for sidebars, footers, and ad placements. This is where you’ll edit HTML for newsletter sign-up boxes, custom banners, or script snippets.
4.1 Block-based widget editor (newer WordPress)
- In the dashboard, go to Appearance → Widgets.
- Click the widget area you want to edit (for example, Main Sidebar or Footer 1).
- Add a Custom HTML block or click on an existing one.
- Edit the HTML directly in the block’s editor.
For example, you might paste this into a Custom HTML block:
<div class="sidebar-cta">
<h3>Get Our Free WordPress Guide</h3>
<a href="/newsletter/" class="btn">Subscribe Now</a>
</div>
4.2 Classic widgets screen (older themes)
- Go to Appearance → Widgets.
- Drag a Custom HTML widget into your chosen widget area.
- Click the widget to expand it, then paste or edit your HTML in the content box.
- Click Save when you’re done, then check the front-end.
http:// URLs on an https:// site. Step 5: Edit Theme HTML Safely in Templates
Sometimes you need to change HTML that isn’t part of a specific post or widget—like the structure of your header, footer, or blog index. This HTML usually lives in your theme’s PHP template files.
5.1 Understand the risks and use a child theme
Theme files like header.php, footer.php, and single.php mix HTML and PHP. Editing them directly is risky because:
- A single syntax error can cause a PHP fatal error and break your site.
- Theme updates can overwrite your changes if you edit the parent theme.
If you’re not comfortable working with theme files, consider reviewing a more focused guide on how to edit WordPress files before making deep structural changes.
5.2 Edit theme files via the Theme File Editor
On many classic themes (including Jannah), you can access theme files directly in the dashboard:
- Go to Appearance → Theme File Editor (or Appearance → Editor on some setups).
- Choose your child theme from the top-right dropdown.
- In the file list, click the template you want to edit (for example, header.php or footer.php).
- Locate the HTML you need to adjust and make small, careful changes.
- Click Update File, then view your site in a new tab.
Example: wrapping a logo in an extra <div> for styling:
<div class="site-logo">
<?php the_custom_logo(); ?>
</div>
If you’re adding styling for new HTML wrappers, put your CSS in Appearance → Customize → Additional CSS instead of editing theme CSS files directly.

5.3 When to use FTP or your hosting file manager
If the Theme File Editor is disabled (common for security reasons) or you need to restore an original file, use your hosting control panel’s File Manager or an FTP client:
- Connect to your server via FTP or cPanel → File Manager.
- Navigate to
wp-content/themes/your-child-theme/. - Download the file you want to edit for backup.
- Edit it locally in a code editor and re-upload it.
Step 6: Preview, Test, and Roll Back Your Changes
Once you’ve edited your HTML, you need to confirm everything still works and looks good across devices. Testing is especially important when you’ve touched theme templates or critical layout areas.
6.1 Preview and test on key devices
- Use the Preview button in the editor to see your changes before publishing.
- Check your page on desktop, tablet, and mobile (resize your browser or use your browser’s device tools).
- Verify that navigation, forms, and important buttons still work correctly.
6.2 Clear caches
If you don’t see your changes immediately, your browser or caching plugin may be serving an older version of the page:
- Clear your browser cache or use a private/incognito window.
- Clear your WordPress caching plugin and any server-level cache (for example, from your host’s control panel).
6.3 Roll back when something breaks
If your layout is broken or you see errors after editing HTML:
- Use the editor’s Undo button or revision history to restore an earlier version of the page or post.
- If you changed a theme file, re-upload the backup you downloaded before editing.
- As a last resort, restore your most recent full site backup.
Wrap Up Your WordPress HTML Changes
Editing HTML in WordPress does not have to be scary. Once you know whether your target is a page, widget, or theme template—and you’re working with backups in place—you can make precise changes without risking your entire site.
Start with the safest layers: the block editor or Classic Editor for content, then move up to widgets and only then to theme files when necessary. With a clear workflow and careful testing, you can fine-tune your layout, add custom components, and keep your WordPress (and Jannah) site clean, fast, and maintainable.
Further Reading
- How to Edit WordPress Themes
- How to Create a Child Theme in WordPress
- How to Edit Footer in WordPress
- Beginner Guide to WordPress Menus and Navigation




