Custom Code & Snippets

Add tracking codes to the head, body or footer, and create targeted HTML, CSS, JavaScript or PHP snippets with placement, page rules, priority and safe mode.

Free Elephanta → Custom Code 2 min read Updated
On this page

Custom Code replaces "insert headers and footers" and code-snippet plugins. Add site-wide tracking codes, or create targeted snippets that run only where you choose.

Code snippets with placement, page rules and status.

The Header · Body · Footer tab has three boxes:

  • Header: printed inside <head> (analytics, meta tags, fonts, verification codes).
  • Body: printed right after <body> (for example Google Tag Manager's noscript).
  • Footer: printed before </body> (chat widgets, pixels).

Choose Top or Bottom position to control ordering against other code, then click Save Header, Body & Footer Code.

#Code snippets

Click Add Snippet to create targeted HTML, CSS, JavaScript or PHP.

#Where to load

Placement Use it for
Site header — inside <head> CSS, meta tags, early scripts
Body — right after <body> noscript tags
Site footer — before </body> Most JavaScript
Before / After post or page content Banners, notices, CTAs
Only where the shortcode is placed Embeds you place manually
Admin area header / footer Admin tweaks
Run everywhere / front end only / admin only PHP functions and hooks

#Page rules and priority

Limit a snippet to the entire site, specific post types, taxonomies or items, with exclusions. Set a priority to control the order of snippets in the same location. You can also duplicate, activate/deactivate and delete snippets.

#PHP snippets and safety

Administrators only

Only administrators can manage Custom Code. PHP snippets are disabled when DISALLOW_FILE_EDIT is set in wp-config.php.

  • Elephanta checks PHP syntax before saving (for example PHP syntax error on line 4).
  • If a PHP snippet causes an error, it is switched off automatically and you get a notice: "The PHP snippet "…" caused an error and was turned off."
  • If you are locked out, add safe mode to wp-config.php to skip all PHP snippets:
define( 'ELEPHANTA_CODE_SAFE_MODE', true );

Log in, fix or deactivate the snippet, then remove the line.

#Example: add Google Analytics 4

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXX');
</script>

Paste it into the Header box and save.