| 开发者 | gkap186 |
|---|---|
| 更新时间 | 2026年1月10日 20:09 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 6.9 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
[varycache_ab v="A"]Content for variant A[/varycache_ab]
[varycache_ab v="B"]Content for variant B[/varycache_ab]
[varycache_ab test="pricing" v="X"]Content for specific test[/varycache_ab]
[varycache_geo country="US"]Content for US visitors[/varycache_geo]
PHP Functions
`// A/B Testing
if ( varycache_is_variant( 'A' ) ) {
// Show variant A content
}
$variant = varycache_get_variant(); // Returns 'A', 'B', etc.
// Geo Targeting
if ( varycache_is_geo( 'US' ) ) {
// Show US-specific content
}
$country = varycache_get_geo(); // Returns 'US', 'RU', etc.`
Page Patterns
Flexible page matching with wildcards and regex:
/ - Homepage only/pricing - Exact page match/blog/* - Single level wildcard/shop/** - Any depth wildcard~^/post/\d+$ - Regular expression (prefix with ~)varycache folder to the /wp-content/plugins/ directoryVaryCache combines page caching with content personalization. Unlike traditional caching plugins that serve the same cached page to everyone, VaryCache can serve different cached versions based on A/B tests, visitor location, or URL parameters.
Yes! You can use VaryCache purely as a page cache. Enable "General Page Cache" in the Page Cache tab and configure which pages to cache. A/B testing, geo targeting, and query parameters are optional features.
VaryCache reads country information from HTTP headers provided by CDNs:
CloudFront-Viewer-CountryCF-IPCountryYes! The shortcodes work with any page builder including Elementor, Gutenberg, Divi, WPBakery, and others. Simply add the shortcode blocks where needed.
Visitors are randomly assigned based on the weights you configure (e.g., 50% variant A, 50% variant B). The assignment is stored in a cookie so they see the same variant on subsequent visits.
No. Search engine bots see the default variant, and the canonical URL remains unchanged. This is the recommended approach per Google's guidelines for A/B testing.
VaryCache includes several Core Web Vitals optimizations:
You can configure specific REST API endpoints to be cached (e.g., /wp/v2/posts). Cached responses are served directly without executing PHP, significantly reducing server load for API-heavy sites.
Cache files are stored in wp-content/cache/varycache/. Settings are stored in wp-content/uploads/varycache/settings.json. Both locations are WordPress-compliant.
Yes, use VaryCache_Cache::clear_cache() in your code. The cache is also automatically cleared when posts are saved or deleted.
Yes, but for A/B testing and geo targeting to work correctly, configure your CDN to: