Created
July 23, 2024 11:05
-
-
Save hamidrezayazdani/f8cf7b92970ca0615adeedd3697de8d5 to your computer and use it in GitHub Desktop.
Force refresh users browser cache for specefic Yoast deleted product redirect
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 | |
/** | |
* 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