Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hamidrezayazdani/f8cf7b92970ca0615adeedd3697de8d5 to your computer and use it in GitHub Desktop.
Save hamidrezayazdani/f8cf7b92970ca0615adeedd3697de8d5 to your computer and use it in GitHub Desktop.
Force refresh users browser cache for specefic Yoast deleted product redirect
<?php
/**
* Clearing the browser cache for all users who have visited your site can be challenging
* since you can’t directly control their browsers.
* However, you can take some steps to ensure that the updated URL is served to everyone
*/
/**
* Force refresh users browser cache for specefic Yoast deleted product redirect
*/
function ywp_set_cache_control_for_specific_product() {
if ( is_product() && get_the_ID() == 123 ) { // 123 = ID of the product that you deleted the its redirect
header( 'Cache-Control: no-cache, must-revalidate' );
header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
}
}
add_action( 'template_redirect', 'ywp_set_cache_control_for_specific_product' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment