# Clear Related Pages From WP Rocket's Cache on Update

> When a post is updated, also clears the WP Rocket cache for the homepage, the blog page, its category and tag archives and the author page, so lists never show stale titles or excerpts.

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: wp-rocket, cache, purge
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/rocket-purge-related-pages/

## Code

```php
$wpide_extra_urls = array(); // e.g. array( home_url( '/news/' ) ).

add_action( 'transition_post_status', function ( $new, $old, $post ) use ( $wpide_extra_urls ) {
    if ( ! function_exists( 'rocket_clean_files' ) || ( 'publish' !== $new && 'publish' !== $old ) || wp_is_post_revision( $post ) || ! is_post_type_viewable( $post->post_type ) ) {
        return;
    }

    $urls = $wpide_extra_urls;
    $urls[] = home_url( '/' );

    if ( 'post' === $post->post_type && get_option( 'page_for_posts' ) ) {
        $urls[] = get_permalink( (int) get_option( 'page_for_posts' ) );
    }

    foreach ( get_object_taxonomies( $post->post_type ) as $taxonomy ) {
        if ( ! is_taxonomy_viewable( $taxonomy ) ) {
            continue;
        }
        foreach ( (array) wp_get_post_terms( $post->ID, $taxonomy ) as $term ) {
            $link = get_term_link( $term );
            if ( ! is_wp_error( $link ) ) {
                $urls[] = $link;
            }
        }
    }

    $urls[] = get_author_posts_url( (int) $post->post_author );

    rocket_clean_files( array_values( array_unique( array_filter( $urls ) ) ) );
}, 20, 3 );
```

## Notes

Does nothing unless WP Rocket is active. Add extra URLs to $wpide_extra_urls, such as a landing page that lists posts.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Clear Related Pages From WP Rocket's Cache on Update" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
