Created
December 31, 2014 12:28
-
-
Save kasparsd/69c47fdf917a65f9ef57 to your computer and use it in GitHub Desktop.
Set custom widget cache expiration (TTL) time in Widget Output Cache plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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