Skip to content

Instantly share code, notes, and snippets.

@bhubbard
Last active May 1, 2026 14:59
Show Gist options
  • Select an option

  • Save bhubbard/4ac728284b16f4acb2756b74be2d3e8d to your computer and use it in GitHub Desktop.

Select an option

Save bhubbard/4ac728284b16f4acb2756b74be2d3e8d to your computer and use it in GitHub Desktop.

Disabling the Elementor Element Cache (introduced as a performance experiment) for specific pages is crucial when dealing with dynamic plugins like BuddyBoss, where content changes based on the user's login status or activity.

Since Elementor does not currently provide a single "on/off" toggle via a public hook for the entire page's Element Cache, the most reliable way to achieve this programmatically is by hooking into the Elementor CSS and cache rendering logic.

Method 1: The Recommended BuddyBoss/URL Snippet This code checks if the current URL contains BuddyBoss keywords (like members, groups, activity) or if it's a specific page ID, and then tells Elementor to bypass caching for those instances.

Add this to your child theme's functions.php or a functional plugin (like Code Snippets):

Method 2: Disabling Cache for Logged-In Users In BuddyBoss sites, the biggest issue is usually that a logged-in user sees a cached version of a page meant for a guest (or vice versa). You can disable the cache for all logged-in users to ensure they always see their personal notifications and profiles correctly.

Why this is necessary for BuddyBoss BuddyBoss relies on Dynamic Content. Elementor's "Element Cache" (found under Elementor > Settings > Performance) saves the HTML of a widget to speed up the site.

If a BuddyBoss "Member Directory" or "Header Notification" widget gets cached:

User A logs in and sees their messages.

The server caches that HTML.

User B logs in and might see User A's notifications or profile data.

Troubleshooting Tips Regenerate CSS: If you still see layout issues after adding the code, go to Elementor > Tools > General and click Regenerate Files & Data.

Clear Object Cache: If you use hosting with built-in caching (like SiteGround or WP Engine) or a plugin like Redis, clear the Object Cache after applying this code.

Global Kill-Switch: If the code above doesn't solve the conflict, it is often safer to disable the feature globally at Elementor > Settings > Performance > Element Cache until Elementor releases more granular controls.

<?php
add_action( 'wp', function() {
if ( is_user_logged_in() ) {
// Forces Elementor to bypass Element Caching for logged-in sessions
add_filter( 'elementor/element/get_common_args', function( $args ) {
$args['_is_static'] = false;
return $args;
});
}
});
<?php
/**
* Disable Elementor Element Cache for BuddyBoss and Specific URLs
*/
add_action( 'wp', function() {
// 1. Define BuddyBoss slugs or specific URLs to exclude
$excluded_slugs = ['members', 'groups', 'activity', 'forums', 'messages'];
// 2. Define specific Page IDs to exclude
$excluded_ids = [123, 456]; // Replace with your actual IDs
$current_url = $_SERVER['REQUEST_URI'];
$is_excluded_slug = false;
foreach ( $excluded_slugs as $slug ) {
if ( strpos( $current_url, '/' . $slug ) !== false ) {
$is_excluded_slug = true;
break;
}
}
// 3. If it's an excluded page, force Elementor to treat it as dynamic
if ( $is_excluded_slug || in_array( get_the_ID(), $excluded_ids ) ) {
// Disables the 'Element Cache' feature logic for this request
add_filter( 'elementor/element/get_common_args', function( $args ) {
$args['_is_static'] = false;
return $args;
});
// Optional: Ensure CSS is loaded internally to prevent stale external files
add_filter( 'pre_option_elementor_css_print_method', function() {
return 'internal';
});
}
}, 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment