Custom Code
The Custom Code plugin puts your own code on your pages
The Custom Code plugin puts your own code on your pages: a tracking script, a stylesheet, a chat widget, a verification tag or a piece of markup. It works like the header and footer plugins of other systems: you keep a list of snippets, and each one has its own place, its own pages and its own on/off switch.
It is a plugin: switch it on under Settings > Plugins. Then open Plugins > Custom Code.
Adding a snippet #
Press Add snippet and fill in:
| Field | What it does |
|---|---|
| Title | Only you see it, to tell snippets apart. |
| Place | In the head, Right after <body>, or Before </body>. Styles, meta tags and analytics suit the head; a tag manager's noscript frame goes right after <body>; most widgets go before </body>. |
| Code | Scripts, <style>, <link rel="stylesheet">, <meta> or any markup. External scripts must use https://. |
| Runs on | See below. |
| Not on these pages | Optional. Pages that never get the snippet. |
| Order | Lower runs first. |
| Active | A snippet that is off stays in the list but is not put on any page. |
Where a snippet runs #
- Public site: the shop, the help pages and the other public pages.
- Public site and client area: the same, plus the signed-in client area and the sign-in pages.
- Everywhere, admin included: also the admin area. Be careful: code there sees everything your staff see.
- Only these pages: you list the pages, one path a line.
Choosing pages #
Paths are written the way they appear in the address bar after your domain:
| Rule | Matches |
|---|---|
/ | The home page only. |
/pricing | That page only. |
/store/* | Every page under /store. |
* | Every page. |
The query string (?a=1), a trailing slash and capital letters do not matter. To run on the whole public site except one page, keep Public site and put that page under Not on these pages. The pages you list work on the public site and the client area; the admin area gets a snippet only when you choose Everywhere.
Safety #
LBM draws the code for you. An inline script gets the page's security nonce, and an external https:// script is allowed through the page's security policy automatically. Every change to a snippet, including switching it on or off, is written to the activity log.
If a page misbehaves after you add code, open the list and switch that snippet off.
If you used an earlier version #
Before this version the plugin had three boxes of code and one setting for where they ran. The first time the list is opened (or a page is shown), each box that had code becomes a snippet named Head code, After <body> code or Before </body> code, running where the old setting said. Nothing changes on your site.
Who can change it #
A role needs the Custom Code box (Change the code on pages) in the role editor. Roles that could configure plugins before keep it until you untick it.
Something missing or wrong? Tell us or contact us.