← Custom Code
Custom Code guides
Everything you need to add code to WordPress safely with the Custom Code plugin.
Add your first snippet
- Go to Custom Code → Add new. Pick the type: HTML, CSS, JavaScript, PHP or plain text.
- Paste your code. PHP needs no
<?phptag; if you paste one, it is removed for you. - Choose where it runs (see below) and, if you like, when it runs (conditions).
- Save in Test mode: only you, logged in as an administrator, see it. Check the site, then switch it to Active.
- Use Is it running? in the sidebar: it opens a page of your site in the background and tells you whether the snippet ran there.
Where code can run
- Run everywhere / front end / admin: PHP that works like code in your theme's functions.php.
- Site: inside <head>, right after <body>, the footer. Analytics, pixels and verification tags go in the header.
- Content: before or after the content, after paragraph N, the middle of a post, excerpts and comments. Archives: between posts on the blog every N posts.
- WooCommerce: 55 hooks on product pages, the shop, cart, checkout, the order received page, My Account and emails, plus shopper actions in JavaScript (added to cart, checkout error, variation chosen).
- Themes and builders: hooks of Astra, GeneratePress, Kadence, OceanWP, Blocksy, Neve, Storefront, Genesis, Divi, Avada, Flatsome, Elementor Pro and Bricks. A Custom Code block, widget, and elements for Elementor, Bricks, Beaver Builder, WPBakery and Avada place a snippet anywhere in a layout.
- Shortcode: choose "Only where I place it" and use
[custom_code id="12"]. - Tick Show locations of inactive plugins to see hooks of plugins you have not installed.
Conditions: run a snippet only for some pages or visitors
- Add a rule such as Page type is Single post. Rules in one group must all match (AND). Add another group for an alternative (OR).
- Free rules: page type, post type, a specific post or page, category or tag, page template, author, page URL, logged in, user role, device and language, and WooCommerce pages.
- Pro rules: date and time, weekday, time of day, visitor country, referrer, URL parameters such as utm_source, cookies, cart subtotal, cart contents, products bought before and number of orders.
- With full-page caching, a cached page is the same for everyone. For device, country or cookie rules, exclude those pages from the cache or prefer CSS and JavaScript checks.
Test mode, crash protection and safe mode
- Lint: a PHP snippet with a syntax error is not activated; the error is shown with its line number.
- Crash protection: if an active PHP snippet causes a fatal error, it is switched off at once and marked "error". Visitors see your site, not a white screen.
- Safe mode: Settings shows a secret link. Opening it turns every snippet off for your browser so you can fix things, even if the admin will not load. You can also add
define( 'WLCC_SAFE_MODE', true );to wp-config.php. - Signed code: snippets changed directly in the database (not through the editor) are held for review instead of running.
- Activity log and alerts: every change is logged, and you can get one email when someone else changes, adds or turns off a snippet.
The AI writer, explainer and fixer
- Click Write with AI and describe what you want. The AI picks the type, location and conditions, writes the code and explains how to test it. Its snippet always arrives in test mode.
- Explain summarises code you pasted, rates its risk and lists the outside services it contacts.
- Fix with AI appears when a snippet is switched off by an error and proposes a corrected version.
- Settings → AI: WALoops AI credits (free allowance; Pro includes $2 a month) or your own Anthropic API key (no limit from us, Anthropic bills you).
The snippet library
- Custom Code → Library has 100+ ready snippets. Search for what you need, for example "hide price" or "google analytics".
- Fill in the short form (an ID, a phone number, a text). Values are escaped for where they land in the code.
- The snippet is added in test mode. Open it, check the site, then make it active.
- Snippets marked Pro unlock with a Custom Code Pro license.
Move from WPCode, Code Snippets and others
- Custom Code → Import / Export lists the snippets of WPCode (Insert Headers and Footers), Code Snippets, Header Footer Code Manager and Simple Custom CSS and JS on this site.
- Imported snippets arrive switched off. Turn on each one after checking it, then deactivate the old plugin.
- Export creates a JSON file you can import on another site. Code Snippets export files work too.
Install Custom Code Pro
- Keep the free Custom Code plugin installed and active: Pro is an add-on.
- Download the Pro zip from the link in your purchase email, then Plugins → Add New → Upload Plugin, and activate it.
- Open Custom Code → Pro license and paste your key. Pro snippets unlock in the library and Pro conditions appear in the editor.
- Updates arrive in Dashboard → Updates like any plugin. To move a license to another site, click "Remove from this site" first.
- Cloud library: in a snippet's Save box, click "Save to cloud library". On any other site with your license, Custom Code → Cloud library → Add to this site.
A snippet does not show up
- Is it Active (not Test mode)? Test mode snippets only run for logged-in administrators.
- Use Is it running? on the page in question. It says whether the snippet ran, or which condition stopped it.
- Clear your cache plugin and CDN cache after changes.
- For PHP, check Custom Code → Activity log for errors. Still stuck? Ask in the support forum; Pro customers can email [email protected].