Skip to content
Arrow keys to move, Enter to open, Esc to closeAll results
Design and Builders · Guides

Bricks Builder Child Theme and Code Setup: Where Every Snippet Belongs

Where every snippet belongs on a Bricks Builder site: child theme, site plugin, snippets plugin or the custom code areas, plus a safe workflow for live edits.

Written by
WPresident Editorial
Topic
Design and Builders

Every Bricks site eventually collects code. A few lines of CSS that the builder controls cannot express. A script that reorders a gallery. A filter that removes image sizes nobody uses. A custom element, a redirect, a tracking snippet from a client. The problem is rarely writing that code. It is deciding where it goes, because a Bricks site gives you at least seven places to put it, and the wrong choice is invisible until something breaks: a theme update that wipes edits, a plugin switched off that takes a feature with it, a snippet stored in a database that no one can review, or a change made on the live site that nobody can roll back.

The single most important idea in this guide is to match each piece of code to the smallest, safest place that can hold it, and to keep everything that is not builder data in version control. Presentation tied to one design belongs in the child theme. Behaviour the site depends on, whatever the design, belongs in a small site plugin. A short, low-risk snippet may live in a snippets plugin. A style or script that only affects one element, one page or the whole site can live in the matching custom code area of Bricks itself. The parent Bricks theme is never edited. Once you apply that rule, the rest of this guide is mostly about doing each part correctly and keeping a safe path from an idea to the live site and back.

This guide starts with a map of all the places code can live and a decision rule for choosing between them. It then explains why the Bricks documentation insists on a child theme and what a child theme does and does not protect you from, and builds a minimal one: a stylesheet header and a functions file, with every line explained. It covers how scripts and styles load and in what order, including the cascade layers Bricks uses, then gives a site-plugin skeleton and compares it with the child theme. After that come the Bricks custom code areas, the role of a snippets plugin, how to keep functions.php from turning into a junk drawer, version control and deployment with a staging site, and a safe procedure for changing code on a live site with a rollback plan, WP-CLI commands included. The last sections cover updating Bricks safely and a list of symptoms and causes.

A few honest boundaries. This is a general guide, not a test report. The Bricks-specific names it uses, such as the settings screens, the style handle for the main stylesheet and the helper function that detects the builder, were checked against the public Bricks documentation, and where a detail depends on your version the text says to check the current documentation. WP-CLI and WordPress functions follow their own documentation. Paths, plugin names and the folder layout are examples to adapt to your site, and every command should be tried on a staging copy before it touches production.

You do not need to be a PHP expert, but you do need to be comfortable with a text editor, with SFTP or Git, and with the idea that a typo in a PHP file can take a whole site offline. That last point is the reason for most of the structure in this guide: keep code small, keep it in files, test it away from visitors, and always know how to switch it off.

Key points

  • Never edit the Bricks parent theme; use a child theme for design-tied code and a small site plugin for behaviour that must outlive the design.
  • Match each snippet to the smallest safe home: element CSS, page code, global code, a snippets plugin, a child theme or a plugin, and keep file-based code in version control.
  • The child theme’s functions file loads in addition to the parent’s, and its stylesheet must be enqueued after the main Bricks stylesheet; Bricks places its own styles in a cascade layer, so unlayered CSS wins.
  • Builder data such as templates, classes and page content lives in the database, so deploy code with Git and move builder data with staging tools or the Bricks import and export.
  • Avoid functions.php sprawl with one file per concern, prefixed names, comments and a loader that fails safe.
  • Change live code only through staging, take a backup first, keep a rollback ready, and know the WP-CLI commands that switch a plugin or theme off when the site will not load.

A map of every place code can live on a Bricks site

Start with the full list, because most people know two or three of these places and use them for everything. The Bricks documentation names several of them in its custom code article, and the developer guides name the rest.

Element-specific CSS. Every element and global class has a CSS group in the style tab. The documentation says to use the %root% placeholder, which Bricks converts to the element ID or class selector, so the rule applies to that element only. It is stored with the page or the class, in the database.

Page-specific code. Page settings have a Custom Code group with custom CSS, header scripts, body header scripts and body footer scripts. The code applies to the page or template you are editing. The documentation notes that script fields appear only to users who may add unfiltered HTML, and that page code is local to the page, so it is the wrong place for behaviour you want site-wide.

Global code. Under the Bricks settings, the Custom code screen offers global custom CSS plus header scripts, body header scripts and body footer scripts, which apply to every page. The global CSS is added at the end of the document head, and the script fields expect you to wrap JavaScript in script tags. It is also stored in the database.

The Code element. It places PHP and HTML, CSS or JavaScript at a specific point in the page output. Executable PHP runs only when code execution is enabled, the current user has the execute-code capability and the saved code carries a valid signature, which the documentation treats as security-sensitive.

A code snippets plugin. A third-party plugin that stores PHP snippets, usually in the database, and runs them on each request. The Bricks documentation mentions it as an acceptable alternative to a child theme for short snippets.

A child theme. A theme folder with its own stylesheet and functions file that sits on top of the Bricks parent theme. This is where the documentation tells you to put your own changes to the theme.

A site plugin. A small plugin that you write for this one site and keep in version control. It is the natural home for functionality that must survive a change of theme.

These fall into two families. File-based code (child theme, site plugin) can be reviewed, diffed, tested and deployed. Database-stored code (element, page and global code, the Code element, most snippets plugins) is edited in the browser, has no history beyond what your backups or revisions provide, and travels with the database rather than with a deploy. Neither family is better in itself; the mistake is to pick one by habit. A rule that works in practice: if the code is PHP, or if it is more than a few lines of CSS or JavaScript that the site depends on, put it in files. If it is a few lines of CSS for one element, put it on that element.

A third distinction matters for risk. A CSS mistake makes something look wrong. A JavaScript mistake breaks a feature, and perhaps the whole page’s scripts. A PHP mistake can take the whole site down with a fatal error, including the admin. The more damage a language can do, the more process it deserves, which is why PHP belongs in files that go through staging and why the later sections spend time on rollback.

Which home for which code

What does the code do?
Styles one element or one global classElement custom CSS with the root placeholder, in the style tab.
A short style or script for one page, or for every pagePage custom code for one page, global custom code for all pages, or a file for anything long.
PHP tied to this design: enqueues, small filters, templates tweaksChild theme, in files under version control.
PHP behaviour the site needs whatever the theme: elements, redirects, integrationsSite plugin, in files under version control.
A starting rule for placing code on a Bricks site, from the smallest scope to the most structural.

Why the child theme exists and what it does not protect

The Bricks developer documentation starts its child theme guide with a warning: do not edit the Bricks theme core files directly, because updating the theme will cause all your changes to be lost. The same message appears on its best-practices page, which tells you to extend Bricks with a child theme or a code snippet plugin. That is the whole reason a child theme exists. The parent theme is replaced wholesale on every update. A child theme is a separate folder that WordPress loads on top of it, so your code is untouched when the parent changes.

Two behaviours of a child theme are worth understanding precisely, because both are easy to get wrong. First, the stylesheet. A child theme’s style.css does not replace the parent’s stylesheet the way its template files can replace the parent’s template files. It is its own file, and it only has an effect if something loads it. WordPress does not enqueue a classic child theme’s style.css for you, so something has to load it, with the right dependency, and the next sections show how. Second, the functions file. The documentation states that a child theme’s functions.php, unlike its stylesheet, does not override the parent’s file. It is loaded in addition to the parent’s functions file, and right before it. That means your code can run before the parent’s code has defined its functions, so a call to a Bricks function at the top level of the file can fail. The fix is to run Bricks-dependent code inside a hook, which fires after the parent has loaded.

It is just as important to know what a child theme does not do. It does not protect builder data. The pages, templates, global classes and settings you create in the builder are stored in the database, not in the theme, so a child theme does not back them up and does not move with a code deploy. It does not isolate you from plugin conflicts. It does not make a bad snippet safe: PHP in a child theme runs on every request exactly as PHP anywhere else does. And it does not follow your design if you change themes: switch away from the child theme and every function in it stops running, which is the reason to put design-independent behaviour in a plugin.

Because Bricks builds templates in the builder rather than in PHP template files, a Bricks child theme usually needs very little: a stylesheet, a functions file, perhaps a folder for scripts and one or two include files. If you find yourself copying parent theme files into the child theme to edit them, stop and ask whether the builder can do it. A copied parent file stops receiving fixes from updates, and that divergence is a cost you pay on every release.

You can build the child theme by hand, as the next section does, or download the ready-made Bricks child theme from your Bricks account, which the documentation describes as a ZIP file you upload like any other theme and activate under Appearance, Themes. The hand-built version is worth reading even if you download one, because it shows what each part is for. Either way, activate the child theme, not the parent, once it is ready; the parent theme must remain installed.

Build a minimal child theme, line by line

A working child theme needs two files, and a third folder keeps things tidy. The structure is a folder named bricks-child inside wp-content/themes, containing style.css, functions.php and an assets folder for scripts and images. The parent theme’s folder is bricks, and the child must point at it by that name.

The stylesheet starts with a comment header that WordPress reads to recognise the theme.

/*
 Theme Name:   Bricks Child
 Description:  Site-specific changes on top of the Bricks parent theme.
 Template:     bricks
 Version:      1.0.0
 Text Domain:  bricks-child
*/

/* Site CSS goes below this line. */

Theme Name is the label shown in the theme list. Template is the one line that matters most: it must equal the folder name of the parent theme, which is bricks. If it does not, WordPress reports that the parent theme is missing and the child cannot be activated. Version is yours to bump when you release. Keep real styles below the comment, or better, in separate files once the stylesheet grows.

The functions file bootstraps everything else. It enqueues the stylesheet using the pattern the Bricks documentation gives, which loads the child stylesheet on the front end and in the canvas, but not in the builder panel, because custom CSS there could affect the builder interface.

<?php
/**
 * Bricks child theme bootstrap.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

add_action( 'wp_enqueue_scripts', function () {
	if ( bricks_is_builder_main() ) {
		return;
	}

	wp_enqueue_style(
		'bricks-child',
		get_stylesheet_uri(),
		[ 'bricks-frontend' ],
		filemtime( get_stylesheet_directory() . '/style.css' )
	);
} );

Line by line. The ABSPATH check stops anyone from running the file directly. The callback is attached to wp_enqueue_scripts, the WordPress action for front-end assets; because it runs inside a hook, it runs after the parent theme has loaded, so bricks_is_builder_main(), the helper the documentation uses to detect the builder panel, exists by then. wp_enqueue_style takes a handle, a source and a dependency list. get_stylesheet_uri() returns the URL of the active theme’s style.css, which is the child’s. The dependency bricks-frontend is the handle Bricks uses for its main frontend stylesheet, according to the asset-loading guide, and listing it makes WordPress print your stylesheet after Bricks’ own. The last argument is the file’s modified time, so the browser fetches a fresh copy whenever you change the file and never needs a manual cache bust.

To add a script, enqueue it in the same callback, after the style, from the assets folder.

	wp_enqueue_script(
		'bricks-child-site',
		get_stylesheet_directory_uri() . '/assets/site.js',
		[],
		filemtime( get_stylesheet_directory() . '/assets/site.js' ),
		true
	);

Here get_stylesheet_directory_uri() builds a URL inside the child folder, the empty array means no dependencies, and the final true loads the script in the footer. Create assets/site.js as an empty file first, then add code to it.

Activate the theme under Appearance, Themes, or with WP-CLI using wp theme activate bricks-child. Then confirm three things: the theme list shows Bricks Child as active, the front end looks unchanged, and the page source contains a link to your stylesheet with a version number. If the site looks unstyled or the builder will not open, switch back to the parent theme and read the debug log before changing anything else.

Loading order: what loads first, and why your CSS wins or loses

A surprising share of code problems on Bricks sites are ordering problems: a style is there, but something else wins; a script runs, but the element it needs is not ready. Knowing the order removes the guesswork.

On the PHP side, WordPress loads the child theme’s functions file, then the parent’s. The theme and plugin code runs, then init fires, then wp_enqueue_scripts runs on the front end. That last hook is where your assets are registered. On the output side, the Bricks asset-loading guide says the main frontend stylesheet, handle bricks-frontend, and the main frontend script, handle bricks-scripts, always load, while libraries such as sliders, lightboxes, maps and animations are loaded only when an element needs them. Your child stylesheet, which lists bricks-frontend as a dependency, prints after it.

The cascade layer system explains most CSS surprises. According to the Bricks cascade layer article, Bricks places its default styles and element CSS in a layer named bricks, with an empty lower-priority sublayer named bricks.reset as a safety net, and some assets in further sublayers for icons, libraries and similar. Styles outside any layer, called un-layered styles, and styles in higher-priority layers take precedence over the bricks layer regardless of selector specificity. The article says this has been enabled by default in current versions, and that the setting lives under the Bricks performance settings as Cascade layer, marked legacy and strongly discouraged to switch off.

Two practical consequences follow. First, your child theme stylesheet is un-layered, so a plain rule there beats a builder-set style on the same property even if the selector is weaker. That is convenient when you want an override, and confusing when you forget you wrote a broad rule such as img { max-width: 400px; } and then wonder why the builder’s width setting does nothing. If a builder style is being ignored, search your CSS before blaming Bricks. Second, the cascade flips for !important: an important declaration in a lower layer beats a normal declaration in a higher one, which is why the bricks.reset sublayer exists. Avoid !important in your own CSS unless there is no other way, and expect it to be hard to override later.

The CSS loading method adds one more variable. By default Bricks writes generated styles for page settings, elements and global classes inline in the page. In the performance settings you can switch to external files, where Bricks writes minified CSS files into the uploads folder under a bricks/css directory, which allows caching by browsers and CDNs. After switching, you must click the button to regenerate CSS files, and the Bricks command-line integration offers the same through wp bricks regenerate_assets, which requires the external files method. Your child stylesheet is unaffected, but anything that cached the old CSS may need a purge.

JavaScript has its own ordering rule: scripts that depend on elements or libraries Bricks initialises must wait for them. A script in the body footer scripts field or in a footer-enqueued file runs after the page markup, but Bricks may still initialise a slider or masonry layout afterwards. For anything that talks to such a library, poll or listen for a ready signal instead of running immediately. The figure summarises the order from request to a styled, scripted page.

The second figure shows the layer rule with real CSS. The builder style sits in a layer named bricks, as the documentation describes. A broad rule in the child stylesheet, which is un-layered, beats it even with a weaker selector. A rule scoped to a class changes only the element you meant to change.

From request to a styled page: the order that matters for code

  1. Child functions file loadsIt runs just before the parent functions file, so Bricks-dependent code belongs inside hooks.
  2. Plugins and theme finish loading, init firesSite plugin code and element registration run here.
  3. wp_enqueue_scripts runsThe main Bricks stylesheet and script are enqueued; libraries only for elements that need them.
  4. Your child stylesheet prints after BricksIt depends on the Bricks frontend handle, and as un-layered CSS it beats layered Bricks styles.
  5. Global and page custom code printCustom CSS goes in the head; footer scripts run last, possibly before a library has initialised.
  6. The browser applies the cascadeLayers, specificity and important flags decide which declaration wins.
The order in which PHP, styles and scripts reach the page on a Bricks site with the default settings.
Rendered output of the code above
Three small panels, each with a button. In the first, only a layered builder style applies and the button is blue. In the second, a broad unlayered button rule from a child stylesheet turns the button orange even though its selector is weaker. In the third, a class-scoped rule turns only the Promo button orange and leaves the Buy now button blue.
A plain HTML and CSS render of the layer rule from this section, using real layered and unlayered CSS in the browser, not a screenshot of the Bricks editor.

A small site plugin for behaviour that must outlive the design

A child theme is tied to a design. The day you change themes, or hand the site to an agency that rebuilds the design, every function in the child theme stops running. If those functions included a redirect rule, a custom element, a tracking integration or a security tweak, the site quietly loses behaviour that had nothing to do with how it looked. A site plugin avoids that. It is an ordinary plugin, written for this one site, that holds the functionality the site depends on, independent of the theme that is active.

A good test is to ask whether the code would still be needed if the design were replaced tomorrow. A custom Bricks element used on many pages, a filter that changes how search works, a function that registers a custom post type, an integration with a payment or email service: yes. A style that adjusts the heading colour, an image size tweak that suits the current layout, an enqueue for the design’s own script: no, those belong in the child theme.

The skeleton below has a main file, an include file and, at the end, an uninstall guard. Create a folder wpr-site-code in wp-content/plugins. The main file carries the plugin header and loads the include files.

<?php
/**
 * Plugin Name: WPR Site Code
 * Description: Site-specific behaviour that must survive a theme change.
 * Version: 1.0.0
 * Requires PHP: 7.4
 * Text Domain: wpr-site-code
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

define( 'WPR_SITE_CODE_VERSION', '1.0.0' );
define( 'WPR_SITE_CODE_FILE', __FILE__ );
define( 'WPR_SITE_CODE_DIR', plugin_dir_path( __FILE__ ) );

require_once WPR_SITE_CODE_DIR . 'inc/assets.php';

The header comment is what makes WordPress list it as a plugin: the plugin name is required, and the version, minimum PHP version and text domain are good practice. The ABSPATH check blocks direct access. The three constants give every include file a version for asset URLs, the main file path (needed by plugins_url) and the folder path for includes. Prefix every constant, function and handle with something unique to you; plugins share one global namespace.

The first include file, inc/assets.php, loads a stylesheet after the Bricks stylesheet, with the same builder check the child theme uses and a guard for the case where Bricks is not the active theme.

<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

add_action( 'wp_enqueue_scripts', function () {
	// Needs the Bricks theme. Do nothing otherwise, and skip the builder panel.
	if ( ! function_exists( 'bricks_is_builder_main' ) || bricks_is_builder_main() ) {
		return;
	}

	wp_enqueue_style(
		'wpr-site-code',
		plugins_url( 'assets/site.css', WPR_SITE_CODE_FILE ),
		[ 'bricks-frontend' ],
		WPR_SITE_CODE_VERSION
	);
} );

The function_exists check matters in a plugin in a way it does not in a Bricks child theme: a plugin loads whatever the active theme is, so Bricks functions may not exist, and calling one would cause a fatal error. The version argument is the plugin version constant, so bump it whenever you change the asset. Finally, a minimal uninstall.php in the plugin root runs when someone deletes the plugin from the dashboard; it starts with a check that WordPress is uninstalling, then removes anything the plugin stored. At the beginning there is nothing to remove, but the guard is a good habit.

<?php
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
	exit;
}

// Delete options created by this plugin here. Nothing to remove yet.

WordPress also supports must-use plugins, a folder whose plugins load automatically and cannot be deactivated from the dashboard. That is useful for code you never want switched off by accident, but it also makes a faulty file harder to disable, so for most sites an ordinary plugin is the safer choice. The figure compares the child theme and the plugin.

Child theme or site plugin

Child themeSite plugin
Runs whenThe child theme is the active themeThe plugin is active, whatever the theme
Survives a change of themeNo, it stops runningYes
Typical contentsEnqueues, design CSS, small filtersElements, integrations, redirects, post types
Switch off to debugSwitch theme, which changes the lookDeactivate one plugin, look unchanged
Needs a Bricks guardNo, the parent is BricksYes, check the Bricks functions exist
The two file-based homes for PHP differ in what survives a design change and in how easily you can switch them off.

The Bricks custom code areas, and where a snippets plugin fits

Bricks offers four built-in places to type code in the browser, and the documentation’s guidance is to choose the smallest location that matches what you need. That is sound advice, with one addition: stop when the code stops being small.

Element custom CSS is for styles that belong to one element or one global class. In the style tab’s CSS group, write rules with the %root% placeholder and Bricks turns it into the right selector. Because the rule moves with the element when you copy or export it, this is the best place for a one-element tweak, and a poor one for anything shared. If you find yourself pasting the same rule onto several elements, make it a global class.

Page custom code holds custom CSS and header, body header and body footer scripts for one page or template. It is right for a script that only that page needs, such as a widget on a landing page. The documentation warns that it does not apply site-wide and that the script fields need the unfiltered HTML capability, so an editor without that capability sees a notice instead.

Global custom code, under the Bricks settings, adds CSS and scripts to every page. The documentation lists analytics snippets, third-party embeds and chat widgets as the intended uses. It is the right home for a tag from a marketing tool that is the same everywhere. It is not the right home for the site’s own JavaScript, because that code deserves a file, a diff and a history.

The Code element prints PHP, HTML, CSS or JavaScript at one exact point in the output. Executable PHP is gated: global code execution must be switched on, the user needs the execute-code capability, and the saved code needs a valid signature. The signature is derived from the WordPress salts, so the documentation says to regenerate signatures after changing the salts or moving the site to an environment with different salts, which is exactly what happens when you copy a site to staging. The documentation offers a constant, BRICKS_LOCK_CODE_SIGNATURES, to stop new signatures from being generated on high-security sites, and a filter, bricks/code/disable_execution, to disable execution entirely from code. If your workflow is file-based, a production site that never needs the Code element’s PHP can switch execution off for good.

// In the site plugin: turn off Code element PHP execution on the site.
add_filter( 'bricks/code/disable_execution', function ( $disable ) {
	return true;
} );

The filter comes from the Bricks documentation, which says returning true disables code execution regardless of the settings screen. Only add it if you are sure nothing on the site depends on executable code, and test on staging first.

A snippets plugin is the fifth option, and the Bricks documentation names it as an acceptable alternative to the child theme for short PHP. Its virtues are speed and convenience: you paste a function and it runs, usually with an on and off switch per snippet. Its costs are the ones already described. The snippets are stored in the database, so they are not in version control and do not travel with a deploy; they run on every request, so a mistake can break the whole site; and over time they become a list of unexplained fragments. Use one for short, low-risk snippets, such as a single filter, that you would be happy to lose, and move anything important to a file. Check whether the plugin offers a safe mode that disables snippets when a fatal error occurs, and keep an exported copy of the snippets in your repository.

The built-in code areas at a glance

ScopeStored in
Element custom CSSOne element or one global classPage or class data in the database
Page custom codeOne page or templatePage settings in the database
Global custom codeEvery page on the siteBricks settings in the database
Code elementOne position in the outputPage data in the database, with a signature for PHP
Snippets pluginEvery request, per snippetUsually the database
Child theme or site pluginEvery request, in filesFiles on disk, in version control
Scope and storage of each place to type code, which decides what you can version, move and review.

Keep functions.php from turning into a junk drawer

Every long-lived WordPress site has a functions file with eight hundred lines of code that nobody dares touch. It starts innocently: a snippet from a forum, a fix for a client, a filter from a tutorial. Soon it holds unrelated concerns, duplicated logic, commented-out experiments, and code whose purpose nobody remembers. The cost shows up as slow debugging and fear of updates.

The cure is structure, applied from the start. Keep the main file small and let it do one job: load other files. Give each concern its own file in an inc folder, named for what it does: enqueue.php, bricks-tweaks.php, security.php. The loader below uses a list, so adding a file is a visible decision, and it wraps each include so that one broken file logs an error instead of taking the site down.

// At the end of functions.php, after the enqueue code.
( function () {
	$parts = [ 'bricks-tweaks' ];

	foreach ( $parts as $part ) {
		$file = get_stylesheet_directory() . '/inc/' . $part . '.php';

		if ( ! is_readable( $file ) ) {
			continue;
		}

		try {
			require_once $file;
		} catch ( Throwable $e ) {
			error_log( 'bricks-child: ' . $part . ' failed to load: ' . $e->getMessage() );
		}
	}
} )();

The anonymous function runs immediately, which keeps the loop variables out of the global scope. get_stylesheet_directory() is the child theme folder. is_readable turns a missing file into a skipped file. require_once loads each file once, and a syntax error or runtime error in it is a catchable Throwable in modern PHP, so the catch block logs it and the rest of the site carries on. Be honest about the limit: this does not catch memory exhaustion, timeouts or every fatal error, and a half-loaded file may have registered some hooks. It is a seatbelt, not a substitute for testing on staging.

A sample include file shows the style: a header comment saying what the file is for, a guard, and one small, named piece of behaviour. This one uses a filter the Bricks documentation describes for trimming the list of image sizes offered when you pick an image from dynamic data in a loop.

<?php
/**
 * Bricks tweaks.
 * Keep the image size picker short: these sizes are never used by the design.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

add_filter( 'bricks/builder/image_size_options', function ( $image_sizes ) {
	unset( $image_sizes['thumbnail'], $image_sizes['1536x1536'], $image_sizes['2048x2048'] );
	return $image_sizes;
} );

Notice the comment explains why, not what. The code already says what. Other habits belong beside the structure. Prefix every function, handle and constant. Use named functions for hooks you might want to remove later or see in a stack trace, and closures for small local ones. Delete dead code instead of commenting it out, because version control remembers it. Before adding any snippet, ask whether the builder already does it, since native settings are maintained for you. And when you adopt code from a forum or a tutorial, read it, understand it and test it on staging; treat pasted PHP as a contribution that needs review, not as a fix.

The same structure applies to a site plugin, and the figure shows both folder layouts side by side. It is a plain HTML and CSS drawing of the file trees, not a screenshot of a file manager.

The second figure walks through the four situations the loader can meet: a good file, a missing file, a file with an error it can catch, and a failure it cannot catch. The last row is the reason staging stays in the workflow.

Rendered output of the code above
Two file trees side by side. The left is the bricks-child theme folder with style.css, functions.php, an inc folder holding enqueue.php and bricks-tweaks.php, and an assets folder holding site.js. The right is the wpr-site-code plugin folder with wpr-site-code.php, uninstall.php, an inc folder holding assets.php and an assets folder holding site.css.
A plain HTML and CSS render of two folder layouts, one for the child theme and one for the site plugin, not a screenshot of a file manager.
Rendered output of the code above
A table of four entries in the loader list. A good file is loaded. A missing file is skipped without an error. A file with a syntax or runtime error is caught and logged, and the rest of the site carries on. A file that exhausts memory or times out is not caught and the request fails.
A plain HTML and CSS render of the four things the loader above can meet, including the one it cannot help with, not a screenshot of any tool.

Version control and deployment with a staging site

Anything that lives in files should live in Git. That covers the child theme and the site plugin, and nothing else on a typical Bricks site. The mistake to avoid is committing the whole WordPress installation: it pulls in core files that WordPress manages, the uploads folder, caches and configuration with secrets. A cleaner approach is one repository for the child theme and one for the site plugin, or a single repository rooted at wp-content that ignores everything except those two folders.

# wp-content/.gitignore: track only the child theme and the site plugin
/*
!/.gitignore
!/themes/
/themes/*
!/themes/bricks-child/
!/plugins/
/plugins/*
!/plugins/wpr-site-code/

The first line ignores everything at the top of the folder, then the exceptions re-include the ignore file itself, the themes and plugins folders, and inside them only the two you own. The Bricks parent theme, other plugins, uploads and caches stay out of Git. The second figure, further down, lists a sample wp-content folder and marks what these rules track and what they ignore. Keep wp-config.php out too, since it holds database credentials and the salts. If you define the Bricks license key as a constant, as the license documentation describes for recent versions, that line lives in the configuration file on each server, not in the repository.

It helps to be clear about what Git does not hold. The builder’s data (pages, templates, global classes, variables, components and most Bricks settings) lives in the database. The media library lives in the uploads folder. Configuration and secrets live in the configuration file and the server. The figure lays these out, because every deployment mistake comes from treating one layer as another.

A sound deployment path has five steps. Commit and tag the change. Deploy the files to staging, using Git pull, a CI job or an rsync command; run it with the dry-run flag first, because the delete option removes files that are not in the source.

$ rsync -avn --delete ./bricks-child/ deploy@staging.example.com:/var/www/staging/wp-content/themes/bricks-child/
$ rsync -av --delete ./bricks-child/ deploy@staging.example.com:/var/www/staging/wp-content/themes/bricks-child/

The first command shows what would change, the second does it. Test on staging, with a staging copy that is recent enough to contain the real builder data the code depends on. Then deploy the same tag to production and run a short smoke test. Finally, clear caches and, if you use external CSS files, regenerate Bricks’ assets.

$ wp cache flush
$ wp bricks regenerate_assets

The second command exists in the Bricks command-line integration and requires the CSS loading method to be set to external files, so skip it on a site that uses inline styles. Purge your page cache and any CDN as well, since cached markup can reference old assets.

Builder data needs its own route. If a deploy needs a new global class, variable or template that the code relies on, move it deliberately. The Bricks global import and export lets you pack selected classes, variables, components, templates and some settings tabs into a ZIP and import it on the target site, with a review of conflicts before applying. Page content moves through your host’s staging push tool or a migration plugin. Be careful with a full database push from staging to production on a live site: it overwrites anything created on production since the copy, such as orders and comments. The WPresident guide to staging sites covers that trade-off.

Environments with different WordPress salts have one more wrinkle. The Bricks documentation says code signatures for executable code are derived from the salts and must be regenerated after a migration to an environment with different ones. Sites that keep PHP in files rather than in Code elements avoid that chore entirely.

What lives where on a Bricks site, and how each layer moves

Code in filesChild theme and site plugin. Version control and deploy by Git, CI or rsync.
Builder data in the databasePages, templates, global classes, variables, components. Move with the host staging tool, a migration plugin or Bricks import and export.
Media in the uploads folderSynced by the staging tool or a file copy, never committed to the code repository.
Configuration and secretsDatabase credentials, salts and the license key constant live in the server configuration file.
The serverPHP version, caches and CDN. Clear them after a deploy and match staging to production.
Code travels with Git, builder data travels with the database or the Bricks import and export, and secrets stay on each server.
Rendered output of the code above
A file tree of a sample wp-content folder. The ignore file, the whole bricks-child theme folder and the whole wpr-site-code plugin folder are marked tracked in green. The Bricks parent theme, another theme, another plugin, uploads, cache, and the index file are marked ignored in grey.
A plain HTML and CSS render of which paths in a sample wp-content folder the ignore file above tracks and which it ignores, not a screenshot of any tool.

A safe workflow for changing code on a live site

The rule is simple to state and hard to follow at five on a Friday: no code change reaches a live site that has not already worked on a copy of it. The workflow below turns that rule into steps with a rollback at the end, so the question is never whether something might go wrong, only how fast you can undo it.

Start by removing the temptation. The WordPress dashboard has built-in theme and plugin file editors that let anyone with the right capability change PHP in the browser, with no backup and no review. Turn them off in wp-config.php with the standard constant, which disables the editors and nothing else.

define( 'DISALLOW_FILE_EDIT', true );

The line must appear before WordPress loads its settings, which means above the comment that tells you to stop editing in the stock configuration file. With the editors off, code reaches the site only by deployment, which is exactly what you want.

Then follow the sequence in the figure. Write and test the change on a development copy or a local site. Run a syntax check on every PHP file you touched, which catches the typo that would otherwise produce a white screen.

$ php -l inc/bricks-tweaks.php
No syntax errors detected in inc/bricks-tweaks.php

Deploy to staging with debug logging on, so notices and warnings are written to the log instead of hidden. Test the page the change affects, the builder, and two or three unrelated pages while logged out, which finds side effects. Watch the browser console and the network panel. Only then plan the production deploy.

Before touching production, take a backup you can actually restore. A database export and a note of the active plugins are the minimum, and a full backup from your host is better.

$ wp db export before-change.sql
$ wp plugin list --status=active
$ wp theme list

The export writes a SQL file to the current folder, and the two list commands record what is active so you can compare afterwards. Deploy the files, using the exact tag you tested on staging, outside peak hours. Bricks has a maintenance mode setting in its own settings if you want visitors to see a holding page during the change; check how it behaves on your site before relying on it, or use your host’s equivalent.

Then run a smoke test with a fixed list: the home page and one deep page load while logged out, the builder opens and a template renders, the admin dashboard loads, a form submits if the site has forms, and the debug log has no new errors. Give yourself a time limit for deciding to roll back, say fifteen minutes, and honour it.

Rollback comes in three strengths. For a code change that works but is wrong, revert the commit or redeploy the previous tag and clear caches. For a change that makes pages fail but leaves the admin reachable, deactivate the site plugin, or activate the parent theme instead of the child, from the dashboard. For a change that causes a fatal error and locks you out, use WP-CLI over SSH. The skip flags tell WP-CLI not to load plugins or themes, so the broken code cannot stop the command that removes it.

$ wp --skip-plugins --skip-themes plugin deactivate wpr-site-code
$ wp --skip-plugins --skip-themes theme activate bricks
$ wp cache flush

The first command switches off the site plugin, the second activates the Bricks parent theme so the child theme’s functions stop running, and the third clears the object cache. If you have no command-line access, rename the plugin’s folder over SFTP; WordPress deactivates a plugin whose files are missing. Be careful with renaming the active child theme’s folder: WordPress may fall back to a default theme, which is not Bricks, so activating the parent theme through WP-CLI is the cleaner fix. After any rollback, restore the database export only if data changed in a way you cannot repair, because a restore also discards everything visitors did since the backup.

Finish by writing down what changed, why, and what you tested. A two-line entry in the repository’s changelog beats memory every time, and it is the first thing a colleague will look for when something odd happens next month. The WPresident guides to WP-CLI and to staging sites go deeper on the commands and the copy workflow.

From idea to live site, with a rollback ready

PlanDefine the change, the pages it affects and the rollback.
DevelopEdit in files on a local or development copy, then lint every PHP file.
StageDeploy to staging with debug logging on and test builder and front end.
Back upExport the database and record active plugins and themes on production.
DeployShip the tagged files, clear caches and regenerate Bricks assets if needed.
Smoke testCheck logged-out pages, builder, admin and the debug log against a fixed list.
DecideKeep the change or roll back within the time limit you set.
RecordWrite the changelog entry with what changed, why and what was tested.
The order of a safe code change; each step exists to catch a different kind of mistake before visitors do.

Updating Bricks without breaking your own code

Your code and Bricks share a surface: the style handle you depend on, the helper functions you call, the hooks you filter, the markup your selectors target. An update can change any of them. The Bricks documentation recommends updating on a staging copy first and reading the changelog before every update, and that advice matters more when you have custom code. Treat each Bricks update as a small release of your own site.

Make the dependency list explicit. In the readme of your repository, write down every Bricks hook, function, style handle and selector your code relies on. In the examples in this guide that list would include the main frontend style handle bricks-frontend, the helper bricks_is_builder_main() and the filter bricks/builder/image_size_options. When the changelog arrives, search it for those names instead of reading everything with equal attention. If a name appears, read that entry carefully; if none does, the risk is lower, though not zero.

One failure mode is worth knowing because it is silent. If you enqueue a stylesheet with a dependency on a handle that is no longer registered, WordPress does not print your stylesheet at all and gives no warning. After an update, your child theme CSS can simply vanish. The test is quick: view the page source on staging after the update and confirm your stylesheet link is present. The figure at the end of this section shows what a good and a bad result look like.

Work through a fixed after-update routine on staging.

  1. Open the builder on a page, a template and a header, and confirm they load without console errors.
  2. View the front end of the same pages, logged out, and compare with production for layout differences.
  3. Check that your child theme or plugin stylesheet and scripts still load, with the expected dependencies and order.
  4. If you use the external CSS files loading method, regenerate the files with the button in the performance settings or the command-line integration, then purge caches.
  5. If the update or the migration changed the WordPress salts, regenerate code signatures before expecting Code element PHP to run, following the code review step the documentation recommends.
  6. Test any custom element and any script that talks to a Bricks library, since library versions can change.
  7. Read the debug log for new notices or deprecations from your files.

Keep a way back. Before updating production, keep a copy of the current theme version and a database backup, and check your Bricks account for how to obtain earlier releases. If the update misbehaves and the problem is not in your code, restore from the backup rather than patching live, and report the problem with a minimal reproduction. The Bricks troubleshooting guide suggests isolating the site on staging, keeping Bricks active and disabling other plugins and custom snippets, to separate a Bricks problem from a conflict; your site plugin and child theme count as custom code in that test, so being able to switch them off quickly pays off.

Finally, keep PHP and the child theme current. A child theme that uses an old PHP feature can break when the host upgrades PHP, so test with the PHP version your host will move to, which most hosts let you set per site on staging.

Rendered output of the code above
Two excerpts of page source. In the good excerpt, a link tag for bricks-frontend-css is followed by a link tag for bricks-child-css with a version number. In the bad excerpt after an update that removed the handle, the bricks-child-css link is missing and a dashed row marks where it should be.
A plain HTML and CSS render of two page-source excerpts, abbreviated and with an example version number, showing a good result and the silent failure described above, not a screenshot of the Bricks editor.

What goes wrong: symptoms, causes and fixes

Most code placement problems repeat. Use this list as a diagnostic order: read the symptom, test the likely cause, and fix at the source.

  • A critical error or white screen right after a change. A PHP fatal in the file you just deployed. Read the debug log, then roll back with the WP-CLI commands above or by redeploying the previous tag. Fix the error on staging.
  • The child theme cannot be activated, or WordPress says the parent is missing. The Template line in style.css does not equal the parent folder name, which should be bricks, or the parent theme is not installed.
  • The child stylesheet does not load. The enqueue code is missing or has a typo, the function is hooked to the wrong action, the builder check is returning true for the page you are viewing, a cache is serving old markup, or the dependency handle is not registered, which makes WordPress skip the file silently.
  • The builder panel looks broken after adding CSS. The stylesheet is loading in the panel. Skip the builder panel with the documented check on bricks_is_builder_main().
  • A builder style does nothing. Your un-layered CSS overrides it, because Bricks puts its element styles in a cascade layer. Search your stylesheet for a broad selector, or an !important, before blaming Bricks.
  • Call to undefined function for a Bricks helper. Either the code runs at the top level of the child functions file, before the parent has loaded, or it lives in a plugin and Bricks is not active. Move it into a hook, and guard plugin code with function_exists.
  • Cannot redeclare a function. The same function name exists in two places, for example the child theme and a snippets plugin. Prefix names and remove the duplicate.
  • It works on staging and not on production. Differences in PHP version, caches, missing builder data or, for executable Code element PHP, different salts and therefore invalid signatures.
  • Changes are saved but not visible. A page cache, a CDN, the browser cache, or external CSS files that were not regenerated. A file version that never changes also keeps old assets alive.
  • A snippet vanished after a migration. It lived in a snippets plugin or a Code element in the database, and the migration did not include it. Move important code to files.
  • Edits disappeared after a theme update. They were made in the parent theme. Redo them in the child theme or a plugin.
  • The wrong theme is active after a folder rename. WordPress fell back to a default theme. Activate the Bricks parent or the child with WP-CLI.

If the cause is not obvious, reduce. Switch the site plugin and the child theme off, one at a time, on staging, and repeat the action. If the problem disappears, add code back in halves until you find the line. Keep Bricks active throughout, as the Bricks troubleshooting guide advises, and clear every cache between tests so you compare like with like.

Checklist

  • Decided where each piece of code lives using the smallest safe home: element CSS, page code, global code, a snippets plugin, a child theme or a site plugin.
  • Never edit the Bricks parent theme or copy its files into the child theme without a clear reason.
  • Created the child theme with a Template line equal to the parent folder name and activated the child, with the parent still installed.
  • Enqueued the child stylesheet with the Bricks frontend handle as a dependency and skipped the builder panel with the documented check.
  • Put code that calls Bricks functions inside hooks, because the child functions file loads before the parent’s.
  • Put behaviour that must outlive the design in a site plugin, with a guard that checks the Bricks functions exist.
  • Checked the CSS for broad or important rules that override builder styles, knowing Bricks styles sit in a cascade layer.
  • Used one include file per concern, a loader that logs a failed include, prefixed names and comments that explain why.
  • Kept the child theme and site plugin in version control, and kept wp-config, secrets and uploads out of the repository.
  • Knew which data lives in the database, and moved builder data with the host staging tool or the Bricks import and export.
  • Disabled the dashboard theme and plugin file editors on production.
  • Linted every changed PHP file and tested on staging with debug logging on before any production deploy.
  • Backed up the database and recorded active plugins and themes before deploying.
  • Prepared a rollback: previous tag, plugin deactivation, and WP-CLI commands with the skip flags for a fatal error.
  • Cleared caches after deploying and regenerated Bricks CSS files if the external files method is used.
  • Listed the Bricks hooks, handles and functions the code depends on, and checked them against each changelog before updating.

About this guide. This is general guidance written by WPresident Editorial from documentation and widely used practice. WPresident has not benchmarked the products or methods described. Interfaces and plan limits change, so check the vendor’s current documentation before you act. Not legal, tax or financial advice. See our editorial policy.

Frequently asked questions

Do I need a child theme for Bricks?

You need one if you add your own PHP or CSS files to the theme, because the Bricks documentation warns that edits to the parent theme are lost when it updates. If you only use the builder and its custom code areas, you can get by without one. Many sites still add one for the enqueue code and a place for small filters. Put design-independent behaviour in a site plugin instead, so it survives a change of theme.

How do I enqueue my CSS in a Bricks child theme?

Hook a function to wp_enqueue_scripts, skip the builder panel with the bricks_is_builder_main check, and call wp_enqueue_style with the child stylesheet URI, the Bricks frontend handle as a dependency, and the file's modified time as the version. That pattern comes from the Bricks child theme guide. The dependency makes your stylesheet print after Bricks' own, and the version makes browsers fetch the new file when it changes.

Why does my custom CSS override my Bricks settings?

Bricks places its default styles and element CSS in a cascade layer, and un-layered styles beat layered ones regardless of selector specificity. Your child theme stylesheet is un-layered, so a broad rule can override a builder setting on the same property. Search your CSS for a general selector or an important flag. Narrow the selector, move the style onto the element or a global class, or remove the rule.

Should I use a code snippets plugin or a child theme?

The Bricks documentation accepts both for extending the theme. A snippets plugin is quick for short, low-risk filters, but snippets usually live in the database, so they are not in version control and may not move with a deploy. A child theme or site plugin keeps code in files you can review, test and roll back. Use a snippets plugin sparingly and move anything important into files.

Where should custom JavaScript go?

Put short, page-specific scripts in the page's custom code footer scripts, and tiny site-wide tags such as analytics in the global custom code settings. Put the site's own JavaScript, anything longer than a few lines, in a file in the child theme or site plugin, enqueued in the footer with a version. That gives you a diff, a history and a deploy path. Always test on the front end, not only in the builder.

How do I recover if a code change breaks the site?

If the admin still loads, deactivate the site plugin or activate the Bricks parent theme. If it does not, use WP-CLI over SSH with the skip flags, for example deactivating the plugin with plugins and themes skipped, then activating the parent theme and flushing caches. Without shell access, rename the plugin folder over SFTP. Then read the debug log, fix the file on staging, and redeploy. Keep a database backup before every change.

What belongs in Git on a Bricks site?

The child theme and the site plugin: your own files. Leave out WordPress core, the Bricks parent theme, other plugins, the uploads folder, caches, and wp-config with its credentials and salts. Builder data such as pages, templates, global classes and settings lives in the database, so Git does not hold it; move it with your host's staging tools, a migration plugin, or the Bricks import and export for supported items.

Can I move global classes and templates between sites without a database push?

Yes, for supported data. The Bricks global import and export lets you export selected theme styles, classes, variables, color palettes, breakpoints, components, templates, fonts, icons, queries and some settings tabs as a ZIP, then import it on another site with a conflict review. It does not replace the full database, and it excludes sensitive settings. Check what it covers in the current documentation before relying on it for a release.

Why do Code element signatures break when I copy a site?

Bricks signs executable code using a hash that depends on the WordPress salts. If the new environment has different salts, the existing signatures no longer match, and the code stops running until it is signed again. The documentation says to regenerate signatures after a migration to an environment with different salts, and after changing salts. Keeping PHP in files in a child theme or plugin avoids the issue.

How do I test code safely before it goes live?

Deploy it to a staging copy of the site with debug logging on, lint the PHP files first, and test the affected page, the builder and several unrelated pages while logged out. Check the console and network panels and the debug log. Back up production before deploying, deploy the same tag you tested, run a fixed smoke test, and decide within a set time whether to keep or roll back.

Does updating Bricks affect my child theme?

The parent theme is replaced on update, but your child theme stays. The risk is a dependency: a style handle, helper function, hook or selector that your code uses could change. Update on staging first, read the changelog for the names your code depends on, confirm your stylesheet still loads, regenerate CSS files if you use external files, and test elements and scripts that talk to Bricks libraries before updating production.

W
Written byWPresident EditorialThe WPresident editorial team. Every article says whether it comes from hands-on use or from documentation, and anything paid for is labelled.

Keep reading

Get the Monthly Launch Report

One email a month: the best of last month's articles, new reviews and what changed in WordPress, without the noise.

No spam. Unsubscribe in one click.

Signed and sealed,
The WPresident
↑↓ move↵ openEsc closeAll results