Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Where code belongs in WordPress depends on what you want it to do: use a Custom HTML block for markup that should appear in a post or page, a Code block to show code as text, and Styles or Additional CSS for styling. Reusable PHP and theme-wide CSS or JavaScript belong in a snippets manager, a child theme, or properly enqueued theme or plugin files—not in a display-only block.
Choose the right place before you paste
First identify the code’s language and scope: is it meant to render in one page, display as an example, style a block or the whole site, or add functionality across the site? This quick comparison separates those jobs.
| Method | Best scope and code | Durability and main limitation |
|---|---|---|
| Code block | Displaying code examples in documentation or a post; any language shown as text. | Stored with content, but does not execute the code. WordPress documentation |
| Custom HTML block | HTML intended for a particular post or page, including permitted embeds. | Stored with the content; WordPress may sanitize scripts or iframes depending on the user’s capabilities. WordPress documentation |
| Styles / Additional CSS | CSS for site-wide styling or a block type. | CSS changes are not overwritten by a theme update, but switching themes can clear them. The scope of a per-block rule matters. WordPress documentation |
| Child theme | Theme-level PHP, CSS, or JavaScript and changes that should remain separate from the parent theme. | Designed to preserve customizations through parent-theme updates; requires file access and a recovery plan. WordPress Developer Handbook |
| Enqueueing | CSS and JavaScript assets for a theme or plugin. | A maintainable way to load assets in the right place, with more setup than pasting a tag. Learn WordPress |
| Snippets plugin | Reusable or site-wide snippets, often PHP. | Can make snippets easier to activate or deactivate in the dashboard, but does not make pasted code safe or remove the need to maintain the plugin. WordPress.org plugin listing |
Put HTML in a Custom HTML block when it should render
In the post or page editor, open the block inserter and choose Custom HTML. You can also start a new paragraph, type /html, and press Enter. Paste only the HTML intended for that location, inspect the block preview, update the page, and check the published result. The block is designed to let you insert code and preview HTML while editing. WordPress: Custom HTML block
A vendor’s embed may include a <script> or <iframe>. If WordPress removes it, that does not necessarily mean you pasted it incorrectly. The Custom HTML documentation says the CSS and JavaScript panels require the unfiltered_html capability. Without that capability, WordPress sanitizes content with wp_kses(), which can remove disallowed tags such as scripts and iframes. Site permissions and hosting policies can therefore determine whether an embed is accepted. WordPress: Custom HTML block
#1 Best Overall
Do not assume that an embed will run merely because the editor accepts its markup. Check whether the account and hosting environment permit it, then verify the published page. If the code is intended to add site functionality rather than display a specific embed, use an appropriate theme, plugin, or approved snippets route instead.
Use the Code block to show code, not run it
The Code block is for adding and displaying snippets for readers to view. It is appropriate for a tutorial, documentation, or a copyable example in PHP, HTML, CSS, or another language. It does not execute the code. WordPress allows a Code block to be transformed into a Custom HTML block, but choose that only when you intend the markup to render. WordPress: Code block
Add CSS through Styles or Additional CSS
For ordinary styling, use the site’s Styles interface rather than placing CSS in an unrelated HTML block. WordPress documents a site-wide custom CSS editor in Styles starting with WordPress 6.2; the Styles interface also supports CSS for a particular block type under Styles > Blocks. The exact controls can depend on the active theme and editor. WordPress: Styles overview
Rank #2
A per-block CSS field may expect declarations only, such as font-style: italic;. A more complex rule or pseudo-class needs a selector and braces. Keep track of whether a rule applies to a block type or the whole site so its effect is not broader than intended.
WordPress says custom CSS changes are not overwritten by a theme update, but are cleared when switching themes. Save a copy of important rules and note their intended scope before changing themes. WordPress: Styles overview
Use a child theme or snippets plugin for reusable PHP
Choose a child theme for theme-level changes
A child theme is appropriate when a change belongs to the theme, adds theme files, or needs to stay separate from the parent theme’s updates. WordPress describes a child theme’s functions.php as a way to modify parent-theme or WordPress functionality and documents loading styles with wp_enqueue_style(). WordPress Developer Handbook: Child Themes
Before editing PHP, make a backup and know how you would recover if a syntax error prevents the site or dashboard from working. Do not paste a PHP function into a Code block and expect it to run: that block is for display.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteChoose a snippets manager when dashboard toggles help
A snippets plugin can provide a dashboard interface for reusable code without maintaining a full custom plugin. The WordPress.org listing describes a snippet as “like a mini-plugin” and says snippets can be activated and deactivated. To install Code Snippets from the dashboard, go to Plugins > Add New, search for Code Snippets, then select Install Now and Activate. The listing also describes a manual ZIP-upload route. Code Snippets on WordPress.org
WPCode is another plugin listed for header and footer scripts and conditional snippets. The directory lists 3+ million active installations for WPCode and 1+ million for Code Snippets in 2026; those counts describe directory installations, not code quality, security, or a recommendation. WPCode on WordPress.org Code Snippets on WordPress.org
Rank #4
A plugin is a management surface, not a safety check. Review the code source, keep backups, and test on staging if available. If the site fails after enabling a snippet, deactivate the most recently enabled snippet using the recovery method available to your host or installation.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Enqueue theme and plugin assets instead of scattering tags
For a theme or plugin you maintain, place CSS and JavaScript in files and enqueue them so WordPress can add them in the appropriate place in the rendered page. The front-end action hook is wp_enqueue_scripts. Learn WordPress: Enqueuing CSS and JavaScript
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Block-editor assets are a separate concern from content readers create. The Developer Handbook documents enqueue_block_editor_assets, enqueue_block_assets, and block.json approaches for block-editor work. WordPress Developer Handbook: Enqueueing assets
Best Value
- If a vendor supplies a script for one page, use the host’s approved embed method or a Custom HTML block if the account permits it.
- If you are building a theme or plugin, put its CSS or JavaScript in an asset file and enqueue it.
- If you need reusable PHP but are not maintaining a full plugin, consider a maintained snippets manager or a child theme according to the code’s scope.
Check whether you use WordPress.com or self-hosted WordPress
Before troubleshooting missing code, identify the environment: WordPress.com, a managed WordPress host, or a self-hosted WordPress.org installation. Similar editor labels do not guarantee the same permissions or available custom-code controls.
WordPress.com says its Custom HTML block can be filtered for security, and that some plans require paid hosting features or a plugin before custom code is accepted. Check the current account’s plan and host rules rather than assuming a self-hosted tutorial applies unchanged. WordPress.com: Custom HTML block
Quick Recap
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.

