Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Created December 31, 2014 12:28
Show Gist options
  • Save kasparsd/69c47fdf917a65f9ef57 to your computer and use it in GitHub Desktop.
Save kasparsd/69c47fdf917a65f9ef57 to your computer and use it in GitHub Desktop.
Set custom widget cache expiration (TTL) time in Widget Output Cache plugin.
<?php
add_filter( 'widget_output_cache_ttl', 'widget_cache_custom_ttl', 10, 2 );
function widget_cache_custom_ttl( $ttl, $widget_args ) {
// Set custom expiration time in seconds for each widget
$map_ttl = array(
'your_widget_id' => 3600,
'another_widget_id' => 87700
);
$widget_id = $widget_args['widget_id'];
if ( isset( $map_ttl[ $widget_id ] ) )
return $map_ttl[ $widget_id ];
return $ttl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment