Skip to content

Instantly share code, notes, and snippets.

@khoipro
Last active May 21, 2024 02:19
Show Gist options
  • Save khoipro/ded5437b4324904bb2d1d785bc87915b to your computer and use it in GitHub Desktop.
Save khoipro/ded5437b4324904bb2d1d785bc87915b to your computer and use it in GitHub Desktop.
[Public] GSC Redirections 404 products to best-selling category
<?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