Created
April 17, 2020 08:15
-
-
Save yanknudtskov/fc372e90ef7f14582e63351158c7e02b to your computer and use it in GitHub Desktop.
In some cases autoptimize JS scripts will be cached in Google and return 404 results if the autoptimize cache has been cleared. To get around that problem this piece of code returns a HTTP 410 Gone for all those scripts that return a 404 because they have been cleared from the Autoptimize cache.
This file contains 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 | |
add_action( 'template_redirect', 'yanco_404_redirect_to_410_for_autoptimize' ); | |
function yanco_404_redirect_to_410_for_autoptimize() { | |
if( is_404() ) { | |
$search = 'cache/autoptimize/js/autoptimize_'; | |
if( strpos( $_SERVER['REQUEST_URI'], $search ) !== false ) { | |
wp_redirect( $_SERVER['REQUEST_URI'], 410 ); | |
exit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment