Last active
May 21, 2024 02:19
-
-
Save khoipro/ded5437b4324904bb2d1d785bc87915b to your computer and use it in GitHub Desktop.
[Public] GSC Redirections 404 products to best-selling category
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 | |
/** | |
* Redirect product 404 page to /best-selling/ page | |
* | |
* @package chuyendev | |
* @author codetot | |
* @since 0.0.1 | |
**/ | |
add_action('template_redirect', function() { | |
if ( is_404() ) { | |
global $wp; | |
$current_url = home_url($wp->request); | |
if ( strpos($current_url, '/product/') !== false ) { | |
wp_safe_redirect( home_url('/best-selling/') ); | |
exit; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment