Skip to content

Instantly share code, notes, and snippets.

@danemorgan
Last active June 30, 2021 08:57
Show Gist options
  • Save danemorgan/b150f0fe4cdd13c7f30894fbbdfe6cb2 to your computer and use it in GitHub Desktop.
Save danemorgan/b150f0fe4cdd13c7f30894fbbdfe6cb2 to your computer and use it in GitHub Desktop.
Sends /page/ paths with a negative category parameter to base uri
/**
* Sends /page/ paths with a negative category parameter to base uri
*/
function csm_no_negative_cat_list() {
if ( isset( $_GET['cat'] ) && $_GET['cat'] == -1 ) {
$uri = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"];
$parsed_uri = parse_url( $uri );
$parsed_path = preg_replace( "/\/page\/[0-9]+/", '', $parsed_uri['path'] );
$redirect = 'https://' . $parsed_uri['host'] . $parsed_path;
wp_redirect( $redirect, 301 );
exit;
}
} add_action( 'pre_get_posts', 'csm_no_negative_cat_list' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment