bricks_update_custom_code
Phase 4.5IntermediateComplexity: 4/10
Update global custom CSS or JavaScript
Overview
Adds custom JavaScript globally or to a specific page. Injects code into either the header (before </head>) or footer (before </body>). Supports append mode (add after existing) or replace mode (overwrite entirely).
Critical: Bricks outputs customScriptsBodyFooter raw into HTML. JavaScript code must be wrapped in <script> tags or it will render as visible text on the page.
Key Features
Position control
Inject in header (before </head>) or footer (before </body>)
Append or replace
Add to existing code or overwrite completely
Dual scope
Global (site-wide) or page-specific injection
When to Use
Adding custom initialization scripts for CDN libraries
Injecting tracking or analytics code
Adding custom animations or interactions via JavaScript
Page-specific JavaScript functionality
Injecting tracking or analytics code
Adding custom animations or interactions via JavaScript
Page-specific JavaScript functionality
Prerequisites
For page scope, you need the page_id
If using append mode, check existing code first with bricks_get_custom_code
If using append mode, check existing code first with bricks_get_custom_code
When NOT to Use
For loading CDN libraries — use bricks_load_cdn_library instead (handles tags + init automatically)
For CSS — use bricks_add_custom_css instead
For CSS — use bricks_add_custom_css instead
Parameters
5 Total Parameters4 Required1 Optional
jsstringREQUIREDJavaScript code to add (without tags)
scopeenumREQUIREDWhere to add: "global" or "page"
Values:
global, pagepage_idnumberoptionalPage ID (required for page scope)
positionenumREQUIREDWhere in HTML to inject: "header" or "footer"
Values:
header, footermodeenumREQUIREDAppend to existing or replace entirely
Values:
append, replaceCode Examples
Add GSAP animation to footer
Inject a GSAP scroll animation globally in the footer
JSON
{
"js": "gsap.from(".feature-card", { scrollTrigger: ".features-grid", y: 60, opacity: 0, stagger: 0.15 });",
"scope": "global",
"position": "footer",
"mode": "append"
}Response
{"success": true}Common Mistakes
JS code renders as visible text on the page
Bricks outputs customScriptsBodyFooter raw — JS must be wrapped in tags. The CDN library loader does this automatically, but bricks_add_custom_js does NOT
Wrong
console.log("hello")Correct
<script>console.log("hello")</script>Tips & Warnings
Tips & Warnings
CRITICAL: JavaScript MUST be wrapped in <script> tags when stored in customScriptsBodyFooter. Bricks renders this content raw into HTML via frontend.php.
- The
bricks_load_cdn_librarytool handles script tag wrapping automatically - When using this tool directly, the agent must provide raw JS — consider wrapping
- Use footer position for most scripts (deferred loading)
Return Values
Related Tools
Technical Details
Changelog
v1.0
Initial release
20250101