Short Answer
If your code belongs on more than one page, or in your site’s header or footer, add it as an HTML snippet in the free WPCode plugin. Pick where it shows, turn it on, and save. If it’s one embed on one page, use the Custom HTML block that’s built into the block editor. Neither method touches your theme files.
Key Takeaways
- Both methods are free. The Custom HTML block is built into WordPress, and every step in Method 1 works on the free version of WPCode.
- A WPCode snippet lives in one place. Edit it once, and every page that shows it updates.
- If your code vanishes after you save, check your user role first. We explain the fix below.
HTML is the code behind every web page. It’s the type of code that creates and structures content.
Maybe you need to add a Google Map, a booking widget, a signup form, or a notice someone gave you. The instructions say to “paste this into your site,” but they don’t tell you where it goes or how to check that it works.
In this guide, we’ll show you the two free places custom HTML can go, how to pick between them, and what to check when your code doesn’t show up.
Use the table of contents below to navigate this article.
- Where Custom HTML Can Go in WordPress (and Which Method to Use)
- Method 1: Add Custom HTML Code to WordPress with WPCode (Free)
- Method 2: Add Custom HTML in the WordPress Block Editor
- Troubleshooting: Custom HTML Not Working in WordPress
- FAQs: Add Custom HTML Code to WordPress
- Pick Your Method and Add Custom HTML Code to WordPress
Where Custom HTML Can Go in WordPress (and Which Method to Use)
There are two good homes for custom HTML on a WordPress site. Which one fits depends on how many pages need the code.
| Custom HTML block | WPCode snippet | WPCode snippet, placed by shortcode | |
|---|---|---|---|
| Best for | One embed on one page | Code on many pages, or in your header or footer | The same code in one exact spot on several pages |
| Where it runs | Only the page you add it to | Wherever you choose: site-wide, before or after content, chosen pages | Wherever you paste the shortcode |
| How you update it | Open each page and edit it | Edit the snippet once | Edit the snippet once |
| Cost | Built into WordPress | Free plugin | Free plugin |
Two other routes come up a lot.
The Custom HTML widget works in classic themes that have widget areas. Block themes, like Twenty Twenty-Five, use the Site Editor instead, so there’s no Appearance » Widgets screen.
And your theme files, like header.php, get overwritten when the theme updates. Your code goes with them.
So if you have one embed for one page, you can skip ahead to Method 2. For everything else, start with Method 1.
Method 1: Add Custom HTML Code to WordPress with WPCode (Free)
For our example, we’ll add a holiday hours notice to the Visit Us page of our coffee shop test site. It’s one page, but we’ll switch it off after the holidays and bring it back next year, so a snippet keeps it in one place.
You can set up the HTML code snippet you want instead of the example we used.
Step 1: Install WPCode
WPCode is the best free snippet plugin. It stores your code outside your theme. Each piece of code lives in its own snippet, and you turn each one on or off with a toggle.
You can do every step in this method with the free version.
To get started, install WPCode from the WordPress plugin directory and activate it. Or go to Plugins » Add New Plugin and search for it in your WordPress dashboard.

After that, you’ll see a new Code Snippets menu in your dashboard.
Step 2: Create an HTML Snippet
Next, go to Code Snippets » + Add Snippet.
This opens the WPCode snippet library with 3,000+ ready-made snippets.
For your own code, you need to start with the blank canvas.
To use it, hover your mouse over the Add Your Custom Code (New Snippet) card, and a + Add Custom Snippet button appears on it.
It only shows while you hover. Click it.

WPCode now asks you to pick a code type. Choose HTML Snippet.

Step 3: Paste Your HTML
First, give your snippet a name you’ll recognize later, like “Holiday Hours”. That’s how you’ll find it in your snippet list.
Here’s the code from our example, if you want to try it:
<div class="hp-holiday-hours">
<p class="hp-holiday-title">Holiday hours</p>
<ul>
<li>Dec 24: 7am to 2pm</li>
<li>Dec 25: Closed</li>
<li>Dec 31: 7am to 4pm</li>
<li>Jan 1: Closed</li>
</ul>
</div>
<style>
.hp-holiday-hours{border:2px solid #2f4a3a;border-radius:10px;background:#f7f1e8;padding:18px 22px;margin:0 0 28px}
.hp-holiday-title{margin:0 0 8px;font-weight:700;font-size:1.15em}
.hp-holiday-hours ul{margin:0;padding-left:20px}
</style>
Then paste your code into the Code Preview box, and check that Code Type in the top right still says HTML Snippet.

The styling sits inside the same snippet, so once you set the page rule in Step 5, it only loads on that page.
Got an embed code from another tool, like a booking widget or a Mailchimp form? Paste it the same way, <script> tags and all. We used one HTML snippet for the Google Preferred Sources button, too.
Only paste code from a tool or person you trust. It runs on your site exactly as written.
Step 4: Choose Where It Appears
Now scroll down to the Insertion box. Leave Insert Method on Auto Insert, and open the Location dropdown.
⚠️ Check the location
A new snippet starts on Site Wide Header. That loads code in your site’s head, the hidden part of the page meant for code visitors don’t see.
That default is right for tracking tags and site verification codes. Site Wide Footer suits scripts designed to load at the bottom of the page, like many chat widgets. Our guide to header and footer code covers both.
But a notice people should see needs to go on the page itself. So for our example, pick Insert Before Content. You’ll find it in the Page, Post, Custom Post Type group.


The same group can place code after the content or after a set paragraph, which is how people insert ads in post content. There are archive page locations, too.
Is your code a tracking pixel? You can paste it in Site Wide Header.
But WPCode’s Conversion Pixels addon (Plus plan and up) can set up a Facebook Pixel and others without pasting any code.
Step 5: Show It Only on the Pages You Choose
Right now, the notice would show before the content of every page and post. We only want it on the Visit Us page.
To do this, scroll to Smart Conditional Logic and switch on Enable Logic.
Next, build the rule. Choose Show, then Page URL, then Contains. In the last box, type part of the page’s address, the text after your domain in the browser bar. We typed /visit/.

Contains matches any address with that text in it. So /visit/ would also catch a page like /visit/parking/. Pick text that only your page’s address has.
Page rules aren’t the only kind. You can also show code only to logged-in visitors, or to specific user roles. Our guide to adding scripts to specific pages walks through more page rules.
Show It on Desktop or Mobile Only (Paid Plans)
The free version shows your snippet on every device, and its desktop and mobile options are greyed out.
Paid plans let you limit a snippet to desktop or mobile visitors. Here’s the Device Type setting on a paid plan.

Paid plans can also turn a snippet on and off on a schedule, or place it before or after a specific page element.
Step 6: Activate, Save, and Check the Page
Scroll back to the top. Flip the toggle from Inactive to Active.
Then click Save Snippet. On a snippet you’ve saved before, this button reads Update.

Now open the page in a private window. In Chrome, press Ctrl+Shift+N.
That way, you see what visitors see, not the logged-in view.
On our site, the holiday hours notice sits right under the page title, above the existing content, and only on the Visit Us page. Your theme decides the exact spacing around it.

After the holidays, flip the toggle back to Inactive and click Update.
The code stays saved, ready for next year.
Place It in One Exact Spot with a Shortcode (Free)
Auto Insert is great when your code belongs before or after the content.
But sometimes you want it in one exact spot, like between two paragraphs on one page. For that, use a shortcode.
In the Insertion box, switch Insert Method to Shortcode. This replaces Auto Insert, so the code won’t also show before the content. As WPCode puts it, the snippet “will only be executed where the shortcode is inserted.”
Save the snippet, and WPCode shows its shortcode, like [wpcode id="427"].
Until you save, the field says “Please save the snippet first.”
The snippet still needs to be Active, and any page rule from Step 5 still applies. If you’ll paste the shortcode on more than one page, switch Enable Logic off first, or the code only shows on pages that match the rule.

Copy it, then open the page in the block editor. Click where you want your HTML to show, type /shortcode, and pick the Shortcode block. Paste the shortcode into it, then save the page.
You can paste the same shortcode on ten pages, and still edit the code in one place.
You can even pass shortcode attributes to change details per page.
Method 2: Add Custom HTML in the WordPress Block Editor
If you only need your code on one page, you don’t need a plugin.
The block editor has three ways to work with HTML. The Custom HTML block is the one for pasting an embed. The other two let you edit the HTML of blocks already on the page.
These steps are for WordPress 7.0 and later, which redesigned the Custom HTML block.
Still on an older version of WordPress?
You won’t see the code window. You type your code straight into the block, and use Preview on the block toolbar to check it. There are no CSS or JavaScript tabs.
Not sure which version you have? Go to Dashboard » Updates.
Add a Custom HTML Block
First, open the page or post you want to edit in the block editor, and click the spot where you want your code to go.
Then type /html in an empty block and pick Custom HTML from the list.

On a paid WPCode plan, you’ll also see WPCode below it. That’s the WPCode block, which places snippets from the editor. On the free plan, it isn’t in the list.
Once the block is added, click the Edit HTML button.

A code window opens with three tabs: HTML, CSS and JavaScript.
Paste your markup in the HTML tab. Styles go in CSS, and scripts go in JavaScript.
Got one embed code with HTML and a <script> tag mixed together? Paste the whole thing in the HTML tab, exactly as the tool gave it.
A live preview on the right shows what you’ll get.
When it looks right, click Update to close the window. Then save the page, and open it in a private window to check the map.

Here’s the map embed from our example:
<iframe src="https://www.google.com/maps?q=Portland,+Maine&output=embed" width="600" height="320" loading="lazy" title="Harbor & Pine on the map"></iframe>
To edit the HTML block later, open the same window again, click Edit code on the block toolbar, as in the screenshot below.

Don’t see the CSS and JavaScript tabs? They only show for users allowed to post unfiltered HTML, which on most sites means Administrators and Editors. The first troubleshooting fix below explains it.
Edit the HTML of Any Block
Want to tweak the HTML of a normal paragraph or image? You can do that without a Custom HTML block.
Select the block, click the Options menu (the three dots) on its toolbar, and choose Edit as HTML.

The block switches to its raw HTML, where you can make your change. Click Edit visually to switch back, and save the page.

Edit the Whole Page in the Code Editor
To see the code for the whole page, click the Options menu at the top right of the editor and choose Code editor. You can also press Ctrl+Shift+Alt+M (Cmd+Shift+Option+M on a Mac).
You’ll see every block as HTML.
Leave the <!-- wp: --> comments alone. WordPress uses them to know where each block starts and ends.

Click Exit code editor when you’re done, then save the page.
All three routes change one page at a time. If the same code sits on ten pages, that’s ten edits, and that’s when a WPCode snippet saves you time.
Troubleshooting: Custom HTML Not Working in WordPress
Find the heading that matches what you see.
“My script or iframe disappeared after I saved.”
This is usually your user role.
WordPress only lets some users post “unfiltered HTML”, meaning code it doesn’t clean up on save. For everyone else, it strips <script> and <iframe> tags when they save.
Here’s who can’t post it:
- On a normal site: Authors and Contributors. Administrators and Editors can.
- On a multisite network: everyone except Super Admins.
Not sure of your role? If you can see the Users menu in your dashboard, open Users » All Users and check the Role column next to your name. If you can’t see that menu, ask whoever runs your site.
The fix is to ask an Administrator or Editor (on multisite, a Super Admin) to add the code for you. WordPress’s guide to roles and capabilities has the full list.
WPCode has its own access settings, and by default only Administrators can manage snippets. It also checks the same unfiltered HTML permission before it saves HTML. So on a single site, this rarely comes up with Method 1.
Are you an Administrator, and the code still vanishes?
Some sites set a WordPress option called DISALLOW_UNFILTERED_HTML in their wp-config.php file. It removes that permission from everyone, Administrators included.
When it’s on, WPCode warns you that it can’t save your code accurately, too. It’s usually there for security, so ask your developer or host whether it’s needed before anyone changes it.
“My code shows up as text on the page.”
Your code probably went into a Paragraph block, and paragraphs show code as plain text.
Move the code into a Custom HTML block or a WPCode snippet, and it will display properly.
“I saved it, but nothing changed.”
Check these three things, in order:
- The snippet is still Inactive. Flip the toggle to Active and click Update.
- Your page rule doesn’t match the page. Open the page and compare its address with the text in your rule. A typo or a missing slash is enough to stop it.
- Your site is showing a saved copy. Clear your caching plugin or host cache, then check the page in a private window.
“Everything below my code looks broken.”
You probably have an unclosed tag, like a <div> with no </div>.
Content after it can get pulled into the open tag.
Find the missing closing tag and add it. HTML errors won’t crash your site, but the code still saves exactly as written.
FAQs: Add Custom HTML Code to WordPress
Can I add custom HTML to WordPress without a plugin?
Yes. Use the Custom HTML block in the block editor, as shown in Method 2. It’s built into WordPress. The catch is that it only adds code to the page you’re editing.
How do I add HTML to my WordPress header?
Use a WPCode HTML snippet with the location set to Site Wide Header. The Custom HTML block can’t reach your site’s head. It’s also how you’d insert scripts like Google Analytics.
What happens to my code if I turn off WPCode?
Your snippets stop running while the plugin is off, so auto-inserted code disappears from your pages. Any shortcode you placed shows as plain text, like [wpcode id="427"], until WPCode is back on. The snippets stay saved, and they come back when you turn WPCode on again. Your theme and content aren’t touched either way.
Will custom HTML slow down my site?
A snippet only adds the code you paste. Heavy third-party embeds, like big video players or chat widgets, are what add load time. Use a page rule so they only load where you need them.
How do I edit or remove custom HTML later?
For a WPCode snippet, go to Code Snippets, open the snippet, and edit it or switch it to Inactive. For a Custom HTML block, open the page and edit or delete the block.
Pick Your Method and Add Custom HTML Code to WordPress
You now know where custom HTML belongs on your site, and what to check when it doesn’t show.
So grab that code you’ve been holding onto. One embed on one page goes in a Custom HTML block. Anything that runs on more than one page goes in a WPCode snippet.
Need ideas for your next snippet? Our countdown timer guide uses the same HTML snippet setup.
Want to keep all your custom code in one place, outside your theme?
Get WPCode for free →
Want to show snippets on desktop or mobile only, schedule them, or place them next to any page element?
See WPCode pricing →
Additional Resources
These guides help you do more with the code you add.
- JavaScript Snippets for WordPress: 13 scripts you can paste with the same steps.
- Best CSS Snippets for WordPress: 16 tested CSS snippets you can copy.
- WPCode Review: what the free and paid versions include.


very useful thanks i just tried it on my website https://axatours.com/ and it worked fine