Test Bricks Templates
This is an advanced test that requires ab split test version 1.4.1 or greater. It uses PHP to replace active bricks templated depending on the test variation. you could replace with any hooks like breakdance, beaver builder or telementor templates. In fact this can extend to any PHP content.
You’ll need to know
- How to add custom PHP to your functions.php file. Plugins like WPCodebox etc. generally run too late to be able to replace templates, so you would need to export to a mu-plugin or similar.
- Your Test ID and Templates that you want to swap’s, ID’s
The Code
Add this to your functions.php or similar. making changes as needed.
// Hops in on server side split test rendering, and swaps bricks templates, too.
add_filter( 'bricks/active_templates', function( $active_templates, $post_id, $content_type ) {
// Your Code Split Test ID (bt_experiments post ID)
$test_id = 456;
$variation = get_or_set_experiment_variation($test_id);
if ($variation === false) {
return $active_templates;
}
// Map variation index to Bricks header template IDs
$headers = [
0 => 123, // Original header
1 => 124, // Variation B
2 => 125, // Variation C
];
if (isset($headers[$variation])) {
$active_templates['header'] = $headers[$variation];
}
return $active_templates;
}, 10, 3 );
Setup Instructions
- Create a new test in ABSPLITTEST → Select “Code Test” as test type
- Set number of variations (e.g., 3 for A/B/C test)
- Configure conversion tracking (click, page visit, form submission, etc.)
- Set targeting if needed (device, user role, URL patterns)
- Publish the test
- Copy the test ID from the URL (e.g.,
post=456) - Add the filter code to your theme’s
functions.phpor a code snippets plugin
Important: Page Caching Must Be Disabled
Page caching must be disabled for server-side template swapping to work correctly. If caching is enabled, all users will see whichever version gets cached. This is not ideal for high traffic sites or slow servers.
Options:
- Disable page caching entirely for tested pages
- Exclude tested pages from cache via URL rules in your caching plugin
- Use cache-busting cookies (some cache plugins can vary cache by
btab_*cookies)
High Traffic Sites: Consider On-Page / Magic / Full page Tests
For high-traffic sites where caching is critical for performance, on-page tests may be a better choice:
| Approach | Caching | How It Works | Trade-off |
|---|---|---|---|
| Code Test (SSR) | ❌ Must be off | PHP swaps templates before render | No caching = higher server load |
| On-Page Test | ✅ Can stay on | Both elements loaded, JS shows/hides correct one | Heavier page weight |
When to Use Each:
Use Code Tests (SSR) when:
- Testing full template swaps (headers, footers, page layouts)
- Site has lower traffic or can handle uncached pages
- You need to test PHP logic or server-side functionality
Use On-Page Tests when:
- Testing smaller elements (headlines, CTAs, buttons, images)
- Site requires caching for performance
- Page weight increase is acceptable