Getting Started
Choose the right plan
Swift Performance is the best choice to speed up your WordPress sites. There are 4 + 1 available plans:
Single plan
You can use Swift Performance with Single plan for 1 WordPress site. It can be the right choice if you have only 1 site, or if you would like to test what can Swift Performance do (you can upgrade your subscription later).
Multi plan
You can use Swift Performance with Multi plan for up to 5 WordPress sites. Regarding that the Multi plan price is very reasonable, if you have at least 2 sites you should choose Multi plan.
Developer plan
As the plan name suggest this plan is the best for developers, who manage many sites. You can use Developer Plan for up to 30 WordPress sites. If you are an agency, or freelancer, who has few clients you should choose Developer plan.
Business plan
We created Business plan for professional speed up experts, who doesn't manage the site, but speed up WordPress sites as a service. Business plan can be used on unlimited sites. For this plan monthly subscription is also available, so you can choose the monthly plan with a reasonable monthly fee as well.
Micro plan
Micro license is a special Single license for bloggers and personal sites. Even if your project generates some income you can use Micro license if your project meets the following requirements: Your site may can generate income from ads, but you can't sell any service/product (including PR articles) on the site. Using Micro license is not allowed for politically active sites.
Install Swift Performance
- Login to My account on musthaveplugins.com
- On the next screen you will see your subscriptions. Choose any active subscription and click to Manage Subscription
- On the next screen click to Download in Swift Performance section
- Login to WordPress admin where you would like to install Swift Performance
- Go to Plugins > Add new and click to upload plugin
- Select the previously downloaded ZIP file and click to install
- Now let Swift Performance to configurate itself
Basic configuration
Caching
What is Caching?
Caching is the core performance optimization in Swift Performance. Instead of executing PHP code and database queries on every page request (which takes 200-800ms), Swift Performance creates static HTML files that can be served in just 5-15ms – a 40-160x speed improvement.
How the Cache Engine Works
The caching process follows this lifecycle:
- Request Arrives – Swift Performance checks if caching is enabled and if the request is cacheable (not POST, not admin, not logged-in unless Logged-in Cache is enabled)
- Cache Load Attempt – Checks
/wp-content/swift-ai/cache/{domain}/{path}/__index/for existing cache file - Cache Hit – If found, serves static file immediately with
Swift3: HITheader - Cache Miss – If not found, WordPress generates the page normally while Swift Performance captures the output
- Output Buffering – Uses
ob_start()to capture the generated HTML - Cacheability Check – Validates the content is cacheable (not password-protected, not 404, not excluded)
- Cache Save – Writes HTML to
__index/index.htmland metadata to__data/data.json - Warmup Queue – Adds URL to optimization queue for image/CSS/JS optimization
Page Priority System
Swift Performance uses a smart priority system that automatically optimizes your most important pages first.
How It Works:
- Initial priorities are assigned based on page type (homepage = highest, blog posts = lower)
- Real visitor data automatically adjusts priorities – most visited pages become more important
- Adapts to changes – priorities reset weekly to reflect current traffic patterns
Real-World Examples:
- Marketing campaign: A new landing page with high traffic automatically becomes high priority for optimization
- Low traffic: A Terms & Conditions page with few visits automatically becomes lower priority
- Main Thread: Swift Performance focuses optimization resources on your most popular pages (typically top 10%)
Result: You don't need to manually configure priorities – Swift Performance automatically optimizes what matters most to your visitors.
Cache Invalidate vs Purge
| Operation | When It Happens | What It Does | Visitor Experience |
|---|---|---|---|
| Invalidate | Post updated, comment added, menu changed, theme/plugin updated |
|
Zero downtime: Visitors continue seeing cached content during rebuild process |
| Purge | Post deleted, manual clear via toolbar, development mode activated |
|
Visitors get fresh (uncached) content immediately, may experience slower page load until cache rebuilds |
Key Difference: Invalidate keeps visitors happy with cached content while rebuilding in the background. Purge forces immediate fresh content at the cost of temporary performance.
Automatic Cache Management Triggers
Swift Performance automatically manages cache based on WordPress actions:
Invalidate (Zero Downtime - Cache Remains):
save_post– Post or page updated (also invalidates homepage and related archives)pre_post_update– Before post updatewp_set_comment_status– Comment approved/unapprovedafter_switch_theme– Theme changed (invalidates all pages)customize_save_after– Customizer settings saved (invalidates all pages)wp_update_nav_menu– Navigation menu updated (invalidates all pages)update_option_sidebars_widgets– Widgets changed (invalidates all pages)activated_plugin/deactivated_plugin– Plugin status changed (invalidates all pages)upgrader_process_complete– WordPress/plugin/theme updated (invalidates all pages)
Purge (Immediate Deletion - Cache Removed):
delete_post– Post or page deleted (purges that page, invalidates homepage and archives)wp_trash_post– Post moved to trash (purges that page, invalidates homepage and archives)delete_attachment– Media file deleted (purges that page, invalidates homepage and archives)save_post– For the specific updated post (purges old version, invalidates related pages)
Smart Invalidation: When a post is updated, Swift Performance also invalidates:
- Homepage (if post appears in recent posts)
- All pages containing loops with that post type
- Category/tag archives where the post appears
- Author archives
- Date-based archives
swift3_purge_cacheaction hook – Custom purge triggers
Nonce Handling in Cached Pages
WordPress nonces expire after 12-24 hours, which can cause "expired nonce" errors on cached pages. Swift Performance handles this in several ways:
- Checksum Filtering – The
swift3_checksum_sourcefilter strips nonce values before calculating page checksums, preventing re-optimization when only nonces change - Fragment Strategy – Wrap forms containing nonces in fragments so they load fresh via AJAX on every page view
- Collage for Logged-in Users – Enable Collage to load user-specific content (including nonces) dynamically while serving cached pages
- Exclude Sensitive Pages – Use
swift3_is_url_excludedfilter or Exclude URLs setting to bypass caching for pages with critical forms - Nonces in cached pages remain valid for their full lifespan (24 hours by default)
When to Use Caching
| Issue | Solution |
|---|---|
| Managed hosting with built-in page caching (Kinsta, WP Engine, etc.) | Disable Swift Performance caching to avoid conflicts |
| Highly personalized sites where every user sees different content | Disable caching or use Logged-in Cache for logged-in users |
| Development/staging environments | Use Development Mode instead of caching |
| Sites with real-time data that must never be stale | Disable caching or use Exclude URLs for specific pages |
Available Hooks & Constants
Filters: swift3_is_request_cacheable, swift3_is_page_cacheable, swift3_cache_buffer, swift3_cache_basedir, swift3_checksum_source
Actions: swift3_cache_done, swift3_page_discovered, swift3_invalidate_cache, swift3_purge_cache
Constants: SWIFT3_CACHE_LIFESPAN, SWIFT3_SEPARATE_DEVICES, INVALIDATE_CACHE_ON_COMMENT
See Developers section for detailed hook documentation and examples.
Optimize CSS
What is Critical CSS?
Critical CSS is the minimum CSS needed to render the above-the-fold content (what users see without scrolling). By inlining this CSS in the <head> and deferring the rest, pages render instantly without waiting for external stylesheets to download.
Impact: Improves First Contentful Paint (FCP) by 0.5-2 seconds and Largest Contentful Paint (LCP) by 0.3-1.5 seconds.
Optimization Levels
| Level | Features | When to Use |
|---|---|---|
| 0 - Disabled |
|
Debugging CSS issues, development environment |
| 1 - Basic |
|
Custom fonts with licensing restrictions, icon fonts, sites with special characters (Chinese, Arabic, etc.) |
| 2 - Full (Recommended) |
|
Recommended for 95% of sites – Maximum performance with standard Latin fonts |
How CSS Optimization Works
Step 1: CSS Collection (During cache prebuild)
- Swift Performance visits the page with a headless browser
- Collects all
<link rel="stylesheet">and<style>tags - Sends CSS URLs and inline styles to the API
Step 2: API Processing
- API renders page in Chrome (viewport: desktop 1441x721px, mobile 541x721px)
- Uses CSS coverage analysis to identify above-the-fold styles
- Generates device-specific critical CSS files
- Level 2 only: Analyzes used characters and creates subset fonts
Step 3: Delivery
- Critical CSS inlined in
<head>with media queries:@media (min-width: 768px)for desktop@media (max-width: 767px)for mobile
- Original stylesheets changed to
rel="swift/stylesheet" - Full stylesheets load after page renders (via JavaScript)
- Level 2: Fonts preloaded with
<link rel="preload" as="font">
Font Optimization (Level 2)
Character Detection:
The API scans your page HTML and extracts all used characters. For example, if your page only uses "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,!? ", only these characters are included in the subset font.
Before Optimization:
@font-face {
font-family: 'MyFont';
src: url('/fonts/myfont.woff2');
/* File size: 150KB, contains 5000+ characters */
}
After Optimization (Level 2):
@font-face {
font-family: 'MyFont';
src: url('/wp-content/swift-ai/cache/.../abc123.woff');
/* File size: 8KB, contains only 80 used characters */
font-display: swap;
}
File Size Reduction: Typically 85-95% smaller (150KB → 8KB)
Troubleshooting
| Issue | Solution |
|---|---|
| Missing font characters | Set to Level 1, or ensure all used characters are in page content during optimization |
| External CSS not optimized | Ensure CSS is from same domain or CORS-enabled |
| Layout shifts (CLS) | Enable Optimize CLS feature |
| Icon fonts broken | Use Level 1 or exclude icon font via swift3_before_assets_optimizer filter |
Available Hooks & Constants
Filters: swift3_skip_optimizer, swift3_before_assets_optimizer, swift3_after_assets_optimizer, swift3_css_layer
Constants: LEGACY_CCSS (force old critical CSS version)
See Developers section for code examples.
Optimize JS
One of the best improvements in Swift Performance is the real javascript optimization. If this feature is enabled Swift Performance will optimize javascript execution and decrease the load on main browser thread. It can speed up your site even for logged in users and on non-cached pages.
JS Delivery
What Does "Offload the Main Thread" Mean?
The main thread is the browser's UI thread that handles rendering, user interactions, and JavaScript execution. When the main thread is busy executing JavaScript, the page becomes unresponsive – users can't click, scroll, or interact.
"Offloading the main thread" means deferring non-critical JavaScript execution until:
- The page has finished rendering (DOMContentLoaded)
- The browser is idle (
requestIdleCallback) - The user interacts with the page (scroll, click, touch)
Impact: Reduces Time to Interactive (TTI) by 30-60% and Total Blocking Time (TBT) by 40-70%.
What is "Delay JS"?
Delay JS means converting <script> tags to <script type="swift/javascript"> so they don't execute immediately. Swift Performance's custom loader then executes them at the optimal time based on:
- Priority – Critical scripts load first, analytics/tracking scripts load last
- Dependencies – jQuery loads before jQuery plugins
- User interaction – Some scripts wait for user activity
- Browser idle time – Low-priority scripts use
requestIdleCallback
Optimization Levels
| Level | Behavior | When to Use |
|---|---|---|
| 0 - Disabled |
|
Debugging JavaScript issues, incompatible theme |
| 1 - Medium (Safe) |
|
Recommended for e-commerce, membership sites, forms-heavy sites |
| 2 - Aggressive (Maximum Performance) |
|
Recommended for blogs, corporate sites, landing pages |
How It Works
Step 1: Script Detection
Swift Performance converts all <script> tags to <script type="swift/javascript"> and moves src to data-src:
<script src="/path/to/script.js"></script>
<script type="swift/javascript" data-src="/path/to/script.js"></script>
Step 2: User Interaction Detection (Level 1)
// Wait for user interaction
['touchstart', 'mousemove', 'scroll', 'keydown', 'click'].forEach(function(event) {
document.addEventListener(event, function() {
loadDeferredScripts(); // Execute all delayed scripts
}, {once: true, passive: true});
});
// Fallback after 3 seconds if no interaction
setTimeout(loadDeferredScripts, 3000);
Step 3: Idle Time Loading (Level 2)
// Use browser idle time
if ('requestIdleCallback' in window) {
requestIdleCallback(function() {
loadDeferredScripts();
}, {timeout: 2000});
} else {
setTimeout(loadDeferredScripts, 1);
}
Step 4: Dependency Management
Swift Performance automatically detects jQuery dependencies and loads jQuery before inline jQuery code:
// Detects this pattern
<script>
jQuery(document).ready(function($) {
$('.slider').slick(); // Requires jQuery
});
</script>
// Ensures jQuery loads first, then executes inline code
Performance Impact
| Metric | Before | Level 1 | Level 2 |
|---|---|---|---|
| Time to Interactive (TTI) | 4.2s | 2.8s (33% faster) | 2.1s (50% faster) |
| Total Blocking Time (TBT) | 890ms | 320ms (64% reduction) | 180ms (80% reduction) |
Compatibility Testing Checklist
Before enabling Level 2, test these scenarios:
- Forms submit properly (contact forms, search forms)
- Sliders/carousels initialize correctly
- Modal popups open/close
- AJAX functionality works (add to cart, filters)
- Video players load (YouTube, Vimeo)
- Image galleries function
- Dropdown menus operate
- Social sharing buttons work
- Live chat widgets load
- Analytics tracking fires
- Cookie consent notices appear
- Payment gateways function (checkout process)
Troubleshooting
| Issue | Solution |
|---|---|
| Forms don't submit | Set to Level 1 or mark form scripts as critical using swift3_before_assets_optimizer filter |
| Sliders don't work | Scripts may need to be marked as critical – see Developers section |
| Console errors about jQuery | Swift Performance auto-detects jQuery dependencies, but some plugins may need manual exclusion |
| Third-party widgets broken | Use swift3_skip_js_optimization filter to exclude specific scripts |
Available Hooks & Constants
Filters: swift3_skip_js_optimization, swift3_js_delivery_tag, swift3_script_type, swift3_before_assets_optimizer
See Developers section for code examples on excluding specific scripts.
Optimize Images
Swift Performance will generate optimized WebP version for all images (including third party and background images) on the fly. Optionally you can also enable Optimize Images on Upload. Swift Performance also can use WebP which has been generated by other plugins, so you can switch instantly.
Optimize Iframes
What It Does
Replaces heavy iframes (YouTube videos, Google Maps, embedded widgets) with optimized placeholders and lazy-loads the actual iframe content only when needed. This can improve LCP by 1-3 seconds and reduce initial page weight by 500KB-2MB per iframe.
Optimization Levels
| Level | What It Does | When to Use |
|---|---|---|
| 0 - Disabled |
|
Debugging iframe issues |
| 1 - Basic Lazy Loading |
|
Basic optimization without screenshots |
| 2 - Full Optimization (Recommended) |
|
Recommended for 95% of sites – Maximum performance |
HTML Transformation
Before Optimization:
<iframe src="https://www.youtube.com/embed/ABC123"></iframe>
After Level 1:
<iframe src=""
data-src="https://www.youtube.com/embed/ABC123?enablejsapi=1"
loading="lazy"></iframe>
After Level 2:
<div class="swift3-iframe-placeholder"
data-src="https://www.youtube.com/embed/ABC123?enablejsapi=1">
<img src="/wp-content/swift-ai/cache/.../iframe-screenshot.webp">
<button class="play-button">▶</button>
</div>
How to Exclude Specific Iframes
Method 1: Exclude by URL Pattern (Recommended)
add_filter('swift3_avoid_lazy_iframes', function($list) {
// Exclude payment gateway iframes
$list[] = 'paypal.com';
$list[] = 'stripe.com';
// Exclude booking systems
$list[] = 'calendly.com';
$list[] = 'booking.com';
return $list;
});
Method 2: Exclude by HTML Attributes
add_filter('swift3_skip_iframe_optimization', function($skip, $tag) {
// Exclude iframes with specific class
if (isset($tag->attributes['class']) &&
strpos($tag->attributes['class'], 'no-lazy') !== false) {
return true; // Skip optimization
}
// Exclude iframes by data attribute
if (isset($tag->attributes['data-critical'])) {
return true;
}
return $skip;
}, 10, 2);
Method 3: Disable on Specific Pages
add_filter('swift3_skip_optimizer', function($skip) {
// Disable all optimization (including iframes) on landing pages
if (is_page('landing-page')) {
return true;
}
return $skip;
});
Automatic Exclusions
Swift Performance automatically excludes these iframes from optimization:
google.com/recaptcha/– Google reCAPTCHAhotjar.com– Hotjar analytics- Payment gateways on checkout pages (WooCommerce, SureCart)
- Iframes with
display:noneorwidth: 0-1px - Iframes with
src="about:blank"
Performance Impact
Real-world metrics from production sites:
- LCP improvement: 1.2s to 2.8s reduction (embedding YouTube videos)
- Page weight: 800KB to 1.5MB reduction per embedded video
- Initial requests: 15-25 fewer HTTP requests on page load
- TTI improvement: 500ms to 1s faster Time to Interactive
Troubleshooting
| Issue | Solution |
|---|---|
| Iframe doesn't load at all | Check browser console for JavaScript errors. Verify REST API is accessible. |
| Payment gateway not working | Already excluded on checkout pages. If issue persists, use Method 1 to exclude specific gateway. |
| Interactive map broken | Consider using Level 1 instead of Level 2, or exclude specific map provider. |
| reCAPTCHA doesn't appear | Already excluded automatically. Check if other optimization is interfering. |
Available Hooks & Constants
Filters: swift3_skip_iframe_optimization, swift3_avoid_lazy_iframes, swift3_skip_optimizer
See Developers section for detailed hook documentation and examples.
Code Optimizer
What It Does
Selectively disables plugins on pages where they're not needed, reducing HTTP requests, database queries, PHP execution time, and memory usage. For example, WooCommerce can be disabled on blog posts, or Yoast SEO can be disabled on the frontend.
How It Works
- Plugin Detection – Identifies the current context (admin, frontend, AJAX, REST API)
- Rule Application – Applies intelligent rules to determine which plugins are needed
- Temporary Deactivation – Removes plugins from
active_pluginsoption temporarily - Restoration – Restores original plugin list after WordPress loads
Built-in Optimizations
- Admin Cache – Caches admin page HTML, saves 200-500ms per admin page load
- Heartbeat Control – Reduces WordPress heartbeat frequency to save server resources
- Emoji Script Removal – Removes emoji detection script (saves 1 HTTP request)
Implemented Plugin Optimizations
Swift Performance includes intelligent rules for these popular plugins:
| Plugin | Optimization Rule |
|---|---|
| Elementor | Disabled on non-Elementor pages, enabled only when editing or viewing Elementor content |
| WooCommerce | Disabled on non-shop pages (blog posts, static pages without products) |
| Yoast SEO | Disabled on frontend, enabled only in admin for SEO configuration |
| Rank Math | Disabled on frontend, enabled only in admin |
| Contact Form 7 | Disabled on pages without CF7 shortcodes |
| Ninja Forms | Disabled on pages without Ninja Forms |
| WPForms | Disabled on pages without WPForms shortcodes |
| Revolution Slider | Disabled on pages without Revolution Slider |
| NextGEN Gallery | Disabled on pages without gallery shortcodes |
| The Events Calendar | Disabled on non-event pages |
| Mailchimp | Disabled on pages without Mailchimp forms |
| Duplicator | Disabled on frontend, enabled only in admin |
| All-in-One WP Migration | Disabled on frontend, enabled only in admin |
| Broken Link Checker | Disabled on frontend, enabled only in admin |
| Duplicate Post/Page plugins | Disabled on frontend, enabled only in admin |
Important: Potential Plugin Dependency Issues
Warning: Code Optimizer can cause issues if one plugin tries to use functions from another plugin that has been disabled on that page.
Example scenario:
- Plugin A is disabled on the current page
- Plugin B tries to call a function from Plugin A
- Result: Fatal error or broken functionality
If you encounter such issues:
- Note which plugins are involved
- Report the issue to Swift Performance support
- Our development team will implement a fix to handle the dependency
- As a temporary workaround, you can disable Code Optimizer or exclude specific plugins
Adding Custom Rules
Example: Disable WooCommerce on Blog Posts
add_action('swift3_code_optimizer_before_check_plugin', function($plugin) {
if ($plugin === 'woocommerce/woocommerce.php') {
Swift3_Code_Optimizer::add($plugin, function() {
// Disable on single blog posts
if (is_single() && get_post_type() === 'post') {
return true; // Disable
}
return false; // Keep enabled
});
}
});
Example: Disable Contact Form 7 Everywhere Except Contact Page
Swift3_Code_Optimizer::add('contact-form-7/wp-contact-form-7.php', function() {
if (is_page('contact')) {
return false; // Keep enabled
}
return true; // Disable everywhere else
});
Safety Features
- Automatic Restoration – Original plugin list is restored after WordPress loads
- Admin Access – Plugins always load in admin areas where they might be configured
- Error Recovery – If a disabled plugin is needed, it will be automatically re-enabled on next request
- Rescue Mode – If Code Optimizer causes issues, a rescue link appears on error pages to disable it
Performance Impact
- Admin pages: 200-500ms faster load times with admin cache
- Frontend: 100-300ms faster when heavy plugins are disabled
- Memory usage: 10-30MB reduction per disabled plugin
- Database queries: 5-20 fewer queries per disabled plugin
Available Hooks
Actions: swift3_code_optimizer_before_check_plugin
See Developers section for detailed examples.
Development Mode
Development Mode temporarily suspends caching and optimization features for two hours (unless disabled beforehand).
Advanced configuration
You can tweak advanced settings if you click "Under the hood" button in Configuration. In most cases you won't need to change these settings, except if you need a quick fix until permanent solution from our dev team.
Caching
Logged in cache
If you enable this option Swift Performance will serve cached pages even for logged in users. In most cases you can simply load cached pages for logged in users as well. If there are some parts which should be personalized, you can use fragments to load them AJAX, or enable Collage to automated detection.
Exclude URLs
With this option, you can exclude pages by URL (or URL part). Write one URL (part) per line, then click to update.
Swift Performance will detect non-cacheable pages automatically, however regarding that there are over 50 000 WordPress plugins and approximetly 30 000 themes, it can happen that Swift Performance can't detect a non-cacheable page.
If you find that there is a plugin or theme related page which always should be excluded, please let us know.
Exclude Post Types
With this option, you can exclude post types. You can select multiple post types.
Just like pages, Swift Performance can detect non-cacheable post types automatically as well. However regarding that there are over 50 000 WordPress plugins, it can happen that Swift Performance can't detect a non-cacheable post type.
If you find that there is a custom post type which always should be excluded, please let us know.
Query String
By default Swift Performance will bypass caching if query string is present in the URL. There are 2 options to overwrite this default behavior:
Ignored query parameters
You can define query parameters which should be ignored. Write one parameter per line. Swift Performance ignores some parameters by default:
utm_source, utm_campaign, utm_medium, utm_expid, utm_term, utm_content, fb_action_ids, fb_action_types, fb_source, fbclid, _ga, gclid, age-verified
Allowed query parameters
You can list query parameters which shouldn't be ignored, but should be cached separately. For example if you add "s" parameter, all of your search results pages will be cached separately. Write one parameter per line.
Bypass Cookies
By default Swift Performance will bypass caching if some specific cookies are set. However you can list any cookies here.
If you find that there is a cookie, which always should be bypassed, please let us know.
Enable GZIP
Usually you won't need to enable GZIP manually, because Swift Performance can detect compression and configure it automatically. However if you have double GZIP issues, then you may need to disable this feature in Swift Performance settings.
Browser Cache
With this option you can let Swift Performance to set the expiry headers for different content types. Usually you don't need to disable this, however in some cases (for example if you are using a CDN with own expiry values), it is unnecessary.
Keep Original Headers
Send original headers for cached pages. If you are using a plugin which send custom headers you can keep them for the cached version as well.
Media
Optimize Images on Upload
Swift Performance will optimize all images (even third party, and background images) on demand. This means, when the cache warmer cache a page, it will pick up all images and optimize them on the actual page. Therefore you don't really need to optimize images on upload, however it can be useful if you would like to serve optimized images for the first (uncached) pageview.
Lazyload Images
Swift Performance is using the native lazyload for images, but improve it. Automatically detects important images and exclude them from lazyloading. You need disable this feature only if you would like to use a different plugin for lazyloading (not recommended).
Smart Image Sizing
Swift Performance will automatically resize images for every used viewport size, and will use responsive images on every pages (even for logged in visitors). You need disable this feature only if you would like to use a different plugin for responsive images (not recommended).
Optimize Rendering
Swift Performance will automatically detect the important images on every pages during the optimization process. These images will be excluded from lazyloading and will be preloaded (using the right responsive size) to improve LCP and FCP scores.
Fragments
General
Swift Performance can load some part of the page dynamically and load the rest from cache. You can enable fragment caching for Elementor Widgets or Gutenberg Blocks in the editor, and specify shortcodes which should be loaded dynamically.
Collage
Collage is a smart feature, which identify dynamic part of a page and load them via AJAX. It can be extremly helpful, if you also enable Logged in cache.
Navigation
With this feature Swift Performance will use smart preload technique (based on network bandwidth and device) to speed up the onsite navigation. With preloading important pages before the user navigate the navigation can be nearly instant. It will improve the field data scores, and the user experience as well.
System
On the system tab you can see your subscription status and disconnect the current site from the subscription.
You can also enable/disable the optimization daemon, which is a background process, and responsible for the optimization process. In most cases you don't need to disable it, however if you are using a shared hosting with limited resources, you may need to disable it.
Integrations
General
Swift Performance is compatible with most plugins and themes out of box, however there are a few third-party plugins, themes, server software and services which are highly integrated with Swift Performance. Most of them doesn't need any configuration (like Elementor, Slider Revolution, WP Bakery, LiteSpeed, etc.), some others can be configured - if it is necessary.
Cloudflare
You can enable autopurge Cloudflare cache, which is recommended if you are using Cloudflare APO, or proxy caching. If you previously used any Cloudflare plugin where your API credentials were set, Swift Performance will find them so you don't need to set them again.
If Cloudflare couldn't be configured automatically you need to choose the authentication mode, and enter Cloudflare e-mail and API password, or Cloudflare API token (recommended).
Once you configured Cloudflare you can enable Proxy caching, which will provide the same performance as Cloudflare APO.
Nginx
If your site is running on Nginx server you need to add the generated rules manually to Nginx config.
You can find the rewrite rules on Nginx tab under Integrations, copy the rules, add them to config and restart Nginx.
On Nginx integration tab you can also verify that rules are up-to-date and working.
Varnish
If Swift Performance detects Varnish you can enable Varnish module on Varnish tab under Integrations. Once you enabled it, Swift Performance will manage Varnish cache as well.
WooCommerce
There are some specific features which can be enabled for a WooCommerce site. You can manage them on WooCommerce tab under Integrations.
Prebuild Variations
If you have separate single pages for variations you should also prebuild them. For this you need to enable Prebuild Variations feature, so Swift Performance will automatically preload, cache and optimize available variation single pages for all products.
Checkout Booster
Swift Performance can preload the checkout page and optimize AJAX fragments to keep the checkout experience fast.
Price Fragments
If you have a multi-currency store, or use visitors' geolocation to calculate VAT on shop/product pages, you can enable Price Fragments feature, to load prices via AJAX, while the rest of the page can be served from cache.
Developers
Swift Performance AI provides a comprehensive set of hooks and constants that developers can use to extend or modify its functionality. This section documents all available filter hooks, action hooks, and constants.
Filter Hooks
Filter hooks allow you to modify data or functionality. Here's a complete list of filter hooks available in Swift Performance AI. You can use these hooks in your theme's functions.php file or in a custom plugin.
Note: Filter hooks should be added using the add_filter() WordPress function. The general syntax is:
add_filter('hook_name', 'callback_function', priority, accepted_args);
where priority is optional (default: 10) and accepted_args is optional (default: 1).
swift3_litespeed_cache_rewrites
Controls whether LiteSpeed cache rewrites should be enabled in the .htaccess file. This filter determines if LiteSpeed caching directives are added to or removed from the .htaccess file.
Parameters:
$enabled(boolean) - Whether cache rewrites are enabled
Default:
Value of swift3_check_option('caching', 'on')
Example:
// Only enable LiteSpeed cache rewrites in production environment
add_filter('swift3_litespeed_cache_rewrites', function($enabled) {
// Check for development environment
if (defined('WP_ENVIRONMENT_TYPE') && WP_ENVIRONMENT_TYPE !== 'production') {
return false;
}
return $enabled;
});
swift3_nginx_cache_rewrites
Controls whether Nginx cache rewrites should be enabled.
Parameters:
$enabled(boolean) - Whether cache rewrites are enabled
Default:
Value of swift3_check_option('caching', 'on')
Example:
// Only enable Nginx cache rewrites in production environment
add_filter('swift3_nginx_cache_rewrites', function($enabled) {
// Check for development environment
if (defined('WP_ENVIRONMENT_TYPE') && WP_ENVIRONMENT_TYPE !== 'production') {
return false;
}
return $enabled;
});
swift3_deactivate_plugins
Filter the list of plugins to deactivate when there are overlapping functionalities.
Default list includes:
- Swift Performance 2.x
- W3 Total Cache
- Autoptimize
- WP Rocket
- WP Fastest Cache
- WP Super Cache
- Hummingbird
- SG Optimizer
- Cache Enabler
- Breeze
- Nitropack
Parameters:
$plugin_files(array) - Array of plugin file paths to deactivate
Example:
// Keep Autoptimize active even when Swift Performance is active
add_filter('swift3_deactivate_plugins', function($plugin_files) {
// Find and remove Autoptimize from the list of plugins to deactivate
foreach ($plugin_files as $key => $plugin_file) {
if (strpos($plugin_file, 'autoptimize') !== false) {
unset($plugin_files[$key]);
}
}
return $plugin_files;
});
swift3_varnish_detected
Allows modification of Varnish detection logic.
Parameters:
$detected(boolean) - Whether Varnish is detected
Default:
Based on HTTP_X_VARNISH header or VARNISH constant
Example:
// Force Varnish detection for specific environments
add_filter('swift3_varnish_detected', function($detected) {
// Force Varnish detection in staging environment
if (defined('WP_ENVIRONMENT_TYPE') && WP_ENVIRONMENT_TYPE === 'staging') {
return true;
}
return $detected;
});
swift3_varnish_not_detected
When Varnish is enabled, Swift will purge Varnish cache if necessary. If the purge request returns an error, Swift will disable Varnish auto purge by default. This filter allows you to override this behavior and keep Varnish enabled even when purge requests fail.
Parameters:
$not_detected(boolean) - Whether Varnish purge failed (true if failed, which would disable Varnish by default)
Default:
Based on HTTP response code (not 200) or missing x-varnish header in response
Example:
// Keep Varnish enabled even when purge requests fail for specific hosts
add_filter('swift3_varnish_not_detected', function($not_detected) {
// Get the current hostname
$hostname = $_SERVER['HTTP_HOST'];
// List of hosts where we want to keep Varnish enabled regardless of purge status
$keep_varnish_hosts = array('staging.example.com', 'dev.example.com');
// If current host is in our list, keep Varnish enabled
if (in_array($hostname, $keep_varnish_hosts)) {
return false; // Return false to prevent disabling Varnish
}
return $not_detected; // Otherwise use default behavior
});
swift3_cloudflare_detected
Filter whether Cloudflare is detected for the site. Swift Performance uses this to determine if Cloudflare-specific optimizations should be applied.
Parameters:
$detected(boolean) - Whether Cloudflare is detected
Default:
Based on HTTP_CF_RAY server variable
Example:
// Force Cloudflare detection to be enabled
add_filter('swift3_cloudflare_detected', '__return_true');
// OR
// Force Cloudflare detection to be disabled
add_filter('swift3_cloudflare_detected', '__return_false');
swift3_jet_blog_detected
Filter whether Jet Blog plugin is detected. Swift Performance uses this to apply specific optimizations for Jet Blog plugin.
Parameters:
$detected(boolean) - Whether Jet Blog plugin is detected
Default:
Based on whether the Jet Blog plugin is active
Example:
// Force Jet Blog detection to be enabled
add_filter('swift3_jet_blog_detected', '__return_true');
// OR
// Force Jet Blog detection to be disabled
add_filter('swift3_jet_blog_detected', '__return_false');
swift3_excluded_edd_pages
Filter the list of Easy Digital Downloads pages to exclude from caching.
Parameters:
$excluded_pages(array) - Array of EDD page IDs to exclude from caching
Default:
Purchase page, success page, failure page, and purchase history page from EDD settings
Example:
// Add additional EDD pages to exclude from caching
add_filter('swift3_excluded_edd_pages', function($excluded_pages) {
// Add a custom EDD-related page to the exclusion list
$excluded_pages[] = 123; // Page ID of a custom EDD-related page
return $excluded_pages;
});
swift3_excluded_surecart_pages
Filter the list of SureCart pages to exclude from caching.
Parameters:
$excluded_pages(array) - Array of SureCart page IDs to exclude from caching
Default:
Default SureCart checkout and account pages
Example:
// Add additional SureCart pages to exclude from caching
add_filter('swift3_excluded_surecart_pages', function($excluded_pages) {
// Add a custom SureCart-related page to the exclusion list
$excluded_pages[] = 456; // Page ID of a custom SureCart-related page
return $excluded_pages;
});
swift3_elementor_widget_settings
Filter Elementor widget settings before processing for fragment caching. This allows you to modify widget settings before they are used to create fragment wrappers.
Parameters:
$settings(array) - The Elementor widget settings$widget_content(string) - The widget content$that(object) - The Elementor widget instance
Default:
Original widget settings from $data['settings']
Example:
// Modify Elementor widget settings to force ajaxify for specific widget types
add_filter('swift3_elementor_widget_settings', function($settings, $widget_content, $widget) {
// Force ajaxify for post widgets
if ($widget->get_name() === 'posts' || $widget->get_name() === 'archive-posts') {
$settings['swift-ajaxify'] = 'yes';
}
return $settings;
}, 10, 3);
swift3_elementor_widget_fragment
Filter whether to create a fragment for an Elementor widget. This allows you to control which widgets should be ajaxified even if they have the 'swift-ajaxify' setting enabled.
Parameters:
$create_fragment(boolean) - Whether to create a fragment for the widget (default: true)$that(object) - The Elementor widget instance
Default:
true
Example:
// Prevent specific Elementor widgets from being ajaxified
add_filter('swift3_elementor_widget_fragment', function($create_fragment, $widget) {
// Don't create fragments for image widgets
if ($widget->get_name() === 'image') {
return false;
}
// Don't create fragments for widgets in specific sections
$section = $widget->get_parent();
if ($section && $section->get_id() === 'header-section') {
return false;
}
return $create_fragment;
}, 10, 2);
swift3_fragment_callback
Filter the JavaScript callback function that will be executed after a fragment is loaded via AJAX. This allows you to add custom JavaScript functionality to fragments.
Parameters:
$callback(string) - The JavaScript callback function (default: empty string)$widget_content(string) - The widget content$that(object) - The Elementor widget instance
Default:
Empty string
Example:
// Initialize Jet Menu after fragment is loaded via AJAX
add_filter('swift3_fragment_callback', function($callback, $content, $that){
// Check if this is a Jet Menu widget
if (in_array($that->get_name(), array('jet-mobile-menu', 'jet-mega-menu'))){
// Return JavaScript to be executed after fragment loads
// This will initialize Jet Menu if it exists
$callback = '(typeof jetMenu !== \'undefined\' && jetMenu.init())';
}
return $callback;
}, 10, 3);
swift3_should_fragment
Controls whether fragment caching should be enabled globally. This is a master switch for all fragment functionality.
Parameters:
$should_fragment(boolean) - Whether fragment caching should be enabled
Default:
true unless swift3_skip_optimizer returns true or nocache query parameter is present
Example:
// Disable fragment caching for specific pages or user roles
add_filter('swift3_should_fragment', function($should_fragment) {
// Disable fragments for specific page templates
if (is_page_template('template-no-fragments.php')) {
return false;
}
// Disable fragments for editors and administrators
if (current_user_can('edit_posts')) {
return false;
}
// Disable fragments for specific post types
if (is_singular('product')) {
return false;
}
return $should_fragment;
});
swift3_elementor_template_types
Filter the list of Elementor template types and their labels. This is used when displaying template type information in the Swift Performance interface.
Parameters:
$labels(array) - Associative array of template type keys and their display labels
Default:
array('wp-post' => 'Post', 'wp-page' => 'Page')
Example:
// Add custom Elementor template types to Swift Performance
add_filter('swift3_elementor_template_types', function($labels) {
// Add support for Elementor Pro template types
$labels['section'] = 'Section';
$labels['header'] = 'Header';
$labels['footer'] = 'Footer';
$labels['single'] = 'Single';
$labels['archive'] = 'Archive';
$labels['popup'] = 'Popup';
// Add custom template type
$labels['custom-type'] = 'Custom Template';
return $labels;
});
swift3_elementor_detected
Filter whether Elementor is detected on the site. This allows you to override the automatic detection of Elementor.
Parameters:
$detected(boolean) - Whether Elementor is detected (default: based on ELEMENTOR__FILE__ constant)
Default:
true if the ELEMENTOR__FILE__ constant is defined
Example:
// Force Swift Performance to use Elementor optimizations even if Elementor is not detected
add_filter('swift3_elementor_detected', '__return_true');
// OR
// Disable Elementor-specific optimizations even when Elementor is installed
add_filter('swift3_elementor_detected', '__return_false');
swift3_excluded_woocommerce_pages
Modifies the list of WooCommerce pages that should be excluded from caching.
Parameters:
$excluded_pages(array) - Array of page IDs to exclude
Default:
Cart, checkout, and account pages
Example:
// Add additional WooCommerce pages to exclude from caching
add_filter('swift3_excluded_woocommerce_pages', function($excluded_pages) {
// Add the thank you page to excluded pages
$thank_you_page_id = get_option('woocommerce_thanks_page_id');
if ($thank_you_page_id) {
$excluded_pages[] = $thank_you_page_id;
}
// Also exclude the wishlist page if using YITH WooCommerce Wishlist
$wishlist_page_id = get_option('yith_wcwl_wishlist_page_id');
if ($wishlist_page_id) {
$excluded_pages[] = $wishlist_page_id;
}
return $excluded_pages;
});
swift3_woocommerce_price_fragment
Filter whether to create a fragment for WooCommerce prices. This controls whether product prices should be loaded via AJAX (as fragments) or included directly in the cached page.
Parameters:
$create_fragment(boolean) - Whether to create a fragment for the price (default: true)$product(WC_Product) - The product object
Default:
true
Example:
// Only create price fragments for variable products
add_filter('swift3_woocommerce_price_fragment', function($create_fragment, $product) {
// Only create fragments for variable products (which may have different prices based on user location)
if ($product->is_type('variable')) {
return true;
}
// For simple products, include the price directly in the cached page
return false;
}, 10, 2);
// OR
// Disable price fragments for specific product categories
add_filter('swift3_woocommerce_price_fragment', function($create_fragment, $product) {
// Get product categories
$terms = get_the_terms($product->get_id(), 'product_cat');
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term) {
// Don't create fragments for products in the 'fixed-price' category
if ($term->slug === 'fixed-price') {
return false;
}
}
}
return $create_fragment;
}, 10, 2);
swift3_ajax_update_{option}_option
Filter the result of updating an option via AJAX.
swift3_http_request_cache_expiry
Controls the expiration time (in seconds) for cached HTTP requests.
Parameters:
$expiry(integer) - Default expiry time (300 seconds)$url(string) - The URL being requested$args(array) - Request arguments
Example:
// Extend cache expiry for specific API endpoints
add_filter('swift3_http_request_cache_expiry', function($expiry, $url, $args) {
// Cache weather API requests longer (1 hour)
if (strpos($url, 'api.weather.com') !== false) {
return 3600; // 1 hour
}
// Cache other external APIs for 10 minutes
if (strpos($url, 'external-domain.com') !== false) {
return 600; // 10 minutes
}
// Cache WooCommerce API requests for less time
if (strpos($url, 'wc-api') !== false) {
return 60; // 1 minute
}
return $expiry;
}, 10, 3);
swift3_http_request_cache_response
Filter the cached HTTP response before returning it. This allows you to modify or validate the cached response data.
Parameters:
$response(array) - The cached response data$url(string) - The URL being requested$args(array) - Request arguments
Default:
The cached transient value
Example:
// Modify cached API responses to ensure data is fresh
add_filter('swift3_http_request_cache_response', function($response, $url, $args) {
// For weather API responses, check if the data is too old
if (strpos($url, 'api.weather.com') !== false) {
// If the timestamp in the response is more than 1 hour old, return false to force a fresh request
if (isset($response['body']) && is_string($response['body'])) {
$data = json_decode($response['body'], true);
if (isset($data['timestamp']) && ($data['timestamp'] + 3600) < time()) {
return false; // Force a fresh request
}
}
}
return $response;
}, 10, 3);
swift3_http_request_cache_url
Filter the URL used for HTTP request cache key generation. This allows you to normalize URLs to improve cache hit rates.
Parameters:
$url(string) - The URL being requested$args(array) - Request arguments
Default:
The original URL
Example:
// Normalize API URLs to improve cache hit rates
add_filter('swift3_http_request_cache_url', function($url, $args) {
// For multilingual sites, remove language code from URL to share cache
if (strpos($url, '/api/') !== false) {
// Remove language path segments like /en/ or /fr/ from the URL
$url = preg_replace('#(https?://[^/]+)/([a-z]{2})/#', '$1/', $url);
}
// Remove tracking parameters that don't affect the response
if (strpos($url, '?') !== false) {
$url_parts = parse_url($url);
if (isset($url_parts['query'])) {
parse_str($url_parts['query'], $params);
// Remove tracking parameters
unset($params['utm_source'], $params['utm_medium'], $params['utm_campaign']);
// Rebuild URL
$url_parts['query'] = http_build_query($params);
$url = Swift3_Helper::build_url($url_parts);
}
}
return $url;
}, 10, 2);
swift3_http_request_cache_args
Filter the arguments used for HTTP request cache key generation. This allows you to normalize or remove request arguments that don't affect the response content.
Parameters:
$args(array) - Request arguments$url(string) - The URL being requested
Default:
The original request arguments
Example:
// Clean up request arguments to improve cache hit rates
add_filter('swift3_http_request_cache_args', function($args, $url) {
// Remove non-deterministic headers that don't affect the response
if (isset($args['headers'])) {
// Remove request-specific headers
unset($args['headers']['X-WP-Nonce']);
unset($args['headers']['X-Requested-With']);
// Remove user-specific headers for shared caching
unset($args['headers']['Cookie']);
unset($args['headers']['Authorization']);
}
// For Query Monitor compatibility, remove its added parameters
if (class_exists('QM_Dispatchers')) {
unset($args['_qm_key']);
}
return $args;
}, 10, 2);
swift3_toolbar_is_page_cacheable
Filter whether a page is cacheable as displayed in the Swift Performance toolbar. This allows you to modify the cacheability status shown in the toolbar without affecting the actual caching behavior.
Parameters:
$is_cacheable(boolean) - Whether the current page is cacheable
Default:
Result of Swift3::get_module('cache')->is_page_cacheable()
Example:
// Always show the current page as cacheable in the toolbar for administrators
add_filter('swift3_toolbar_is_page_cacheable', function($is_cacheable) {
// Only modify the toolbar display for administrators
if (current_user_can('manage_options')) {
return true;
}
return $is_cacheable;
});
// OR
// Show specific pages as non-cacheable in the toolbar for testing purposes
add_filter('swift3_toolbar_is_page_cacheable', function($is_cacheable) {
// Get current URL
$current_url = Swift3_Helper::get_current_url();
// Mark specific test pages as non-cacheable in the toolbar
if (strpos($current_url, '/test-page/') !== false) {
return false;
}
return $is_cacheable;
});
swift3_collage_result_{type}
Filter the result of a collage operation by type. The {type} placeholder is replaced with the specific collage type (e.g., 'admin_bar'). This allows you to modify the HTML content returned by different collage operations.
Parameters:
$result(string) - The HTML content generated by the collage operation$data(array) - Data passed to the collage operation
Default:
The HTML content generated by the specific collage operation
Example:
// Modify the admin bar collage content
add_filter('swift3_collage_result_admin_bar', function($result, $data) {
// Remove specific items from the admin bar
$result = preg_replace('/<li id="wp-admin-bar-updates".*?<\/li>/s', '', $result);
// Add custom notification to the admin bar
$result = str_replace('</ul></div>', '<li id="custom-notification"><a href="#">Custom Notification</a></li></ul></div>', $result);
return $result;
}, 10, 2);
swift3_collage_admin_bar_request
Filter the admin bar collage request parameters. This allows you to modify the data used to generate the admin bar fragment request.
Parameters:
$request(array) - Array containing collage request data: [0] => 'collage', [1] => queried_object_id, [2] => 'admin_bar'
Default:
array('collage', $wp_the_query->queried_object_id, 'admin_bar')
Example:
// Modify the admin bar collage request to include additional data
add_filter('swift3_collage_admin_bar_request', function($request) {
// Add a custom identifier to the request
$request[3] = 'custom_admin_bar';
// Add user role information to the request
if (is_user_logged_in()) {
$user = wp_get_current_user();
$request[4] = $user->roles[0];
}
return $request;
});
swift3_admin_cache_notices
Filter the HTML content of admin notices before they are cached. This allows you to modify, remove, or add notices in the WordPress admin area when using Swift Performance's admin cache.
Parameters:
$notices(string) - The HTML content of admin notices
Default:
The output buffer content from the admin_notices hook
Example:
// Remove specific admin notices from the cache
add_filter('swift3_admin_cache_notices', function($notices) {
// Remove update notifications
$notices = preg_replace('/<div class="update-nag".*?<\/div>/s', '', $notices);
// Remove specific plugin notices
$notices = preg_replace('/<div class="notice" id="woocommerce-message".*?<\/div>/s', '', $notices);
// Add a custom notice
$custom_notice = '<div class="notice notice-info"><p>This is a custom cached notice.</p></div>';
$notices .= $custom_notice;
return $notices;
});
swift3_admin_cache_menu
Filter the WordPress admin menu array before it is cached. This allows you to modify the admin menu structure when using Swift Performance's admin cache.
Parameters:
$menu(array) - The global WordPress admin menu array
Default:
The global $menu array
Example:
// Modify the admin menu before it's cached
add_filter('swift3_admin_cache_menu', function($menu) {
// Remove specific menu items
foreach ($menu as $key => $item) {
// Remove the Comments menu item
if (isset($item[2]) && $item[2] === 'edit-comments.php') {
unset($menu[$key]);
}
// Remove the Tools menu item
if (isset($item[2]) && $item[2] === 'tools.php') {
unset($menu[$key]);
}
}
// Add a custom menu item
$menu[] = array(
0 => 'Custom Menu',
1 => 'read',
2 => 'custom-menu',
3 => '',
4 => 'menu-top',
5 => 'custom-menu-top',
6 => 'dashicons-admin-generic'
);
return $menu;
});
swift3_code_optimizer
Determines whether code optimization should be enabled for the current request.
Parameters:
$enabled(boolean) - Whether optimization is enabled
Default:
true
Example:
// Disable code optimization for specific post types
add_filter('swift3_code_optimizer', function($enabled) {
global $post;
// Disable for landing pages
if (isset($post) && $post->post_type === 'landing_page') {
return false;
}
// Disable for pages with specific template
if (is_page_template('template-fullwidth.php')) {
return false;
}
// Disable for specific page IDs
if (is_page(array(123, 456, 789))) {
return false;
}
return $enabled;
});
swift3_skip_optimizer
Controls whether optimization should be skipped for the current request. This is a master switch that affects all optimization features including caching, CSS/JS optimization, and fragments.
Parameters:
$skip(boolean) - Whether to skip optimization (default: false)
Default:
false, but automatically returns true if ?preview, ?nocache, or ?swift-test-page query parameters are present
Example:
// Skip optimization for specific user agents or conditions
add_filter('swift3_skip_optimizer', function($skip) {
// Skip optimization for page builders
if (isset($_GET['elementor-preview']) || isset($_GET['et_fb']) || isset($_GET['fl_builder'])) {
return true;
}
// Skip optimization for specific user roles
if (current_user_can('editor') || current_user_can('shop_manager')) {
return true;
}
// Skip optimization for specific page templates
if (is_page_template('template-custom.php')) {
return true;
}
// Skip optimization based on custom cookie
if (isset($_COOKIE['disable_optimization'])) {
return true;
}
return $skip;
});
swift3_cache_device
Controls the suffix added to cache files to differentiate between device types.
Parameters:
$suffix(string) - The device suffix, default is '-mobile' for mobile devices when SWIFT3_SEPARATE_DEVICES is defined
Example:
// Create separate cache files for tablets
add_filter('swift3_cache_device', function($suffix) {
// Check if it's a tablet using a detection function
if (function_exists('wp_is_tablet') && wp_is_tablet()) {
return '-tablet';
}
// Otherwise return the default suffix
return $suffix;
});
swift3_gutenberg_block_fragment
Filter whether to create a fragment for a Gutenberg block. This allows you to control which blocks should be loaded via AJAX as fragments.
Parameters:
$create_fragment(boolean) - Whether to create a fragment for the block (default: true)$block(array) - The block data array
Default:
true for blocks with the isSwiftPerfrormanceLazyloaded attribute set to true
Example:
// Prevent specific Gutenberg blocks from being ajaxified
add_filter('swift3_gutenberg_block_fragment', function($create_fragment, $block) {
// Don't create fragments for specific block types
if (isset($block['blockName'])) {
// Don't create fragments for image blocks
if ($block['blockName'] === 'core/image') {
return false;
}
// Don't create fragments for blocks in the 'acf' namespace
if (strpos($block['blockName'], 'acf/') === 0) {
return false;
}
}
// Don't create fragments for blocks with specific attributes
if (isset($block['attrs']['data-no-fragment']) && $block['attrs']['data-no-fragment']) {
return false;
}
return $create_fragment;
}, 10, 2);
swift3_shortcode_fragment
Filter whether to create a fragment for a shortcode. This allows you to control which shortcodes should be loaded via AJAX as fragments, even if they are in the shortcode fragments list.
Parameters:
$create_fragment(boolean) - Whether to create a fragment for the shortcode (default: true)$shortcode(string) - The shortcode tag$atts(array) - The shortcode attributes
Default:
true for shortcodes listed in the shortcode fragments setting
Example:
// Conditionally prevent specific shortcodes from being ajaxified
add_filter('swift3_shortcode_fragment', function($create_fragment, $shortcode, $atts) {
// Don't create fragments for the contact form shortcode on the contact page
if ($shortcode === 'contact-form-7' && is_page('contact')) {
return false;
}
// Don't create fragments for gallery shortcodes with specific IDs
if ($shortcode === 'gallery' && isset($atts['id'])) {
$excluded_gallery_ids = array(123, 456, 789);
if (in_array($atts['id'], $excluded_gallery_ids)) {
return false;
}
}
// Don't create fragments for any shortcodes in the sidebar
global $wp_current_filter;
if (in_array('dynamic_sidebar_before', $wp_current_filter) || in_array('dynamic_sidebar_after', $wp_current_filter)) {
return false;
}
return $create_fragment;
}, 10, 3);
swift3_option_{key}
Filter the value of any Swift Performance option when it's retrieved. Replace {key} with the actual option name (e.g., swift3_option_caching).
This is a powerful hook that allows you to dynamically modify any option value at runtime without changing the stored value in the database.
Parameters:
$value(mixed) - The current option value
Example:
// Force caching off in development environment
add_filter('swift3_option_caching', function($value) {
if (defined('WP_DEBUG') && WP_DEBUG) {
return ''; // Disable caching
}
return $value;
});
// Dynamically adjust cache lifespan based on post type
add_filter('swift3_option_cache-lifespan', function($value) {
if (is_singular('product')) {
return 3600; // 1 hour for products
}
return $value;
});
swift3_option_not_set_{key}
Filter the default value returned when an option is not set in the database.
Parameters:
$default(mixed) - The default value
Example:
// Provide a custom default for an option
add_filter('swift3_option_not_set_custom-setting', function($default) {
return 'my_default_value';
});
swift3_update_option_{key}
Filter the value before an option is updated in the database.
Parameters:
$value(mixed) - The value about to be saved
Example:
// Sanitize value before saving
add_filter('swift3_update_option_custom-url', function($value) {
return esc_url_raw($value);
});
swift3_check_option_{key}
Filter the result of checking an option value with a comparison operator.
Parameters:
$result(boolean) - The comparison result$value(mixed) - The value being compared$compare(string) - The comparison operator (=, !=, <, >, <=, >=, CONTAINS, IN)
swift3_get_template
Filter template content before it's returned. Useful for modifying JavaScript or PHP templates used by the plugin.
Parameters:
$content(string) - The template content$template(string) - The template name$type(string) - The template type ('tpl' or 'js')
swift3_ua_string
Filter the User Agent string used for HTTP requests made by Swift Performance.
Parameters:
$ua_string(string) - The User Agent string$context(string) - The context ('default', 'cache-hit', 'litespeed-purge-request', etc.)
Default:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Swift Performance
Example:
// Customize User Agent for cache warming requests
add_filter('swift3_ua_string', function($ua_string, $context) {
if ($context === 'cache-hit') {
return 'Swift Performance Cache Warmer/1.0';
}
return $ua_string;
}, 10, 2);
swift3_cache_buffer
Filter the page buffer before caching decisions are made. This allows you to modify the content before Swift Performance analyzes it.
Parameters:
$buffer(string) - The page HTML content
Example:
// Add custom markers to the HTML before caching
add_filter('swift3_cache_buffer', function($buffer) {
return str_replace('