When cached with WP-Rocket, there are times when you need to delete the cache of a specific page or post. This is because, when the content of the post changes, the Archive pages where this post is displayed also need to be updated.
Of course, if you modify it in the WordPress editor, the cached content will be automatically refreshed, so usually there is no need to worry about this. However, if the content has been changed by modifying it with a custom function in functions.php or directly in the database, the plugin may not recognize the change, and the previously cached content may still be displayed.
WP-Rocket Menu
Delete All Cache
It would be simple to delete all cache from the WP-Rocket menu on the admin page.
Delete Page Cache
After logging into the admin, when you display the corresponding page, you can use the menu to delete the current page cache from the top admin menu.
Admin Page
To delete just one post or one page, you can do so from the post or page list as shown in the image below.
Delete During Programming
To ensure that the cache is also updated when modifying a post during programming tasks, you can use coding like the one below.
REST API
curl -X GET "https://yourwebsite.com/wp-json/wp-rocket/v1/purge?url=https://yourwebsite.com/sample-page"
-H "Authorization: Bearer YOUR_API_KEY"
- Change the
https://yourwebsite.com/sample-page
part to the URL of the page you want to delete. YOUR_API_KEY
is the WP Rocket API key.
PHP
if ( function_exists( 'rocket_clean_post' ) ) {
rocket_clean_post( 123 ); // 123 is the ID of the page to be deleted
}