Skip to content

Instantly share code, notes, and snippets.

@tylertadej
Last active April 17, 2021 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylertadej/7dcace802f64cfef1612a3c698397d1c to your computer and use it in GitHub Desktop.
Save tylertadej/7dcace802f64cfef1612a3c698397d1c to your computer and use it in GitHub Desktop.
WP Rocket homepage cache clear hook
// Clear the cache of specific posts after the homepage is cleared.
// This is useful if you have a feed of items on the homepage and other pages with the same feed.
// WP Rocket source: https://github.com/wp-media/wp-rocket/blob/443f2e1b902c592bd517cbaa641571bb2ddce1a5/inc/functions/files.php#L613
// Clean with POST ID. Tip: Pages have IDs too so this should work for them as well.
function rocket_clean_posts_with_home_cleaning( $root = '' ) {
$posts_list = [
1
];
foreach ($posts_list as $post_id) {
rocket_clean_post( $post_id );
}
}
add_action( 'after_rocket_clean_home', 'rocket_clean_posts_with_home_cleaning' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment