Implementing Tests on Your Website¶
This section covers the different ways to implement A/B tests on your WordPress website using BoastPress AB Testing.
Using the Shortcode Method¶
The primary way to implement tests is through shortcodes. Shortcodes allow you to place test content anywhere that supports WordPress shortcodes.
Basic Shortcode Usage¶
The basic syntax for the AB Testing shortcode is:
[ab_test test="123"]
Where 123
is the ID of your test. You can find this ID in the test list or on the test edit page.
Shortcode Placement Options¶
You can place the shortcode in various locations:
In Posts and Pages¶
- Edit the post or page where you want to display the test
- Position your cursor where the test content should appear
- Insert the shortcode:
[ab_test test="123"]
- Update the post or page
In WordPress Templates¶
To add a test to a WordPress template file:
<?php echo do_shortcode('[ab_test test="123"]'); ?>
Place this code in your theme's template files where you want the test content to appear.
In Widgets¶
You can add shortcodes to text widgets:
- Go to Appearance > Widgets
- Add a Text or Custom HTML widget to your desired widget area
- Insert the shortcode:
[ab_test test="123"]
- Save the widget
In Page Builders¶
Most page builders support shortcodes:
- Add a Text or HTML element in your page builder
- Insert the shortcode:
[ab_test test="123"]
- Save your changes
AJAX vs. Non-AJAX Implementation¶
BoastPress AB Testing offers two methods for delivering test content:
Non-AJAX Mode¶
In non-AJAX mode, test content is generated when the page is loaded:
- Pros: Faster initial page load, no JavaScript dependency
- Cons: Not compatible with caching plugins or CDNs
This is the default mode and works well for sites without caching.
AJAX Mode¶
In AJAX mode, test content is loaded after the page has rendered:
- Pros: Compatible with caching plugins and CDNs
- Cons: Slight delay in content appearance, requires JavaScript
To enable AJAX mode:
- When creating or editing a test, check the "Use AJAX" option
- Or enable it globally in A/B Tests > Settings
When to Use AJAX Mode¶
Use AJAX mode when:
- Your site uses caching plugins (WP Super Cache, W3 Total Cache, etc.)
- Your site uses a CDN (Cloudflare, MaxCDN, etc.)
- You need consistent test delivery across cached pages
Performance Considerations¶
AJAX mode adds an additional HTTP request for each test on the page. For high-traffic sites, consider:
- Limiting the number of tests per page
- Using session-based testing to reduce server load
- Implementing proper browser caching for AJAX responses
Cache Compatibility¶
How AJAX Mode Works with Caching¶
When using AJAX mode:
- The page is loaded from cache with placeholder elements for test content
- JavaScript makes an AJAX request to get the appropriate test variation
- The placeholder is replaced with the actual test content
This ensures that each user gets the correct test variation, even when pages are cached.
Configuring Caching Plugins¶
For optimal performance with caching plugins:
WP Super Cache¶
- Go to Settings > WP Super Cache
- Under "Advanced", ensure "Don't cache pages for known users" is checked
- Click "Update Status"
W3 Total Cache¶
- Go to Performance > Page Cache
- Under "General", ensure "Don't cache pages for logged in users" is checked
- Click "Save Settings"
Other Caching Plugins¶
Most caching plugins have similar options. Look for settings related to: - User-specific caching - Dynamic content handling - AJAX/JavaScript compatibility
Advanced Implementation Techniques¶
Dynamic Test Selection¶
You can dynamically select which test to display based on page context:
<?php
// Determine which test to show based on page
$test_id = is_front_page() ? 123 : 456;
echo do_shortcode("[ab_test test=\"$test_id\"]");
?>
Conditional Test Display¶
You can conditionally display tests based on user roles or other factors:
<?php
// Only show test to logged-in users
if (is_user_logged_in()) {
echo do_shortcode('[ab_test test="123"]');
} else {
echo 'Default content for non-logged in users';
}
?>
Multiple Tests on One Page¶
You can include multiple tests on a single page:
<div class="header">
[ab_test test="123"]
</div>
<div class="content">
[ab_test test="456"]
</div>
<div class="footer">
[ab_test test="789"]
</div>
Each test operates independently, with its own tracking and variations.
Troubleshooting Implementation Issues¶
Test Not Displaying¶
If your test isn't displaying:
- Verify the test is active in the admin dashboard
- Check that the test ID in the shortcode is correct
- Ensure the test has at least one version
- Confirm that one version is set as the default
AJAX Loading Issues¶
If test content isn't loading in AJAX mode:
- Check browser console for JavaScript errors
- Verify that your theme properly enqueues jQuery
- Ensure your server allows AJAX requests
- Check for JavaScript conflicts with other plugins
Content Flicker in AJAX Mode¶
If you notice content flickering when using AJAX mode:
- Go to A/B Tests > Settings
- Adjust the "AJAX Loading Delay" setting
- Consider adding custom CSS to control the transition
In the next section, we'll explore advanced configuration options for your A/B tests.