Last active
June 30, 2021 08:57
-
-
Save danemorgan/b150f0fe4cdd13c7f30894fbbdfe6cb2 to your computer and use it in GitHub Desktop.
Sends /page/ paths with a negative category parameter to base uri
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
/** | |
* 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