Add utility function to get clean URL

Enough with this annoyance!
This commit is contained in:
Tetrakern 2023-06-11 16:43:26 +02:00
parent ca3ef92068
commit 3acb67a8f5
2 changed files with 29 additions and 4 deletions

View File

@ -1569,4 +1569,32 @@ if ( ! function_exists( 'fictioneer_minify_html' ) ) {
}
}
// =============================================================================
// GET CLEAN CURRENT URL
// =============================================================================
if ( ! function_exists( 'fictioneer_get_clean_url' ) ) {
/**
* Returns URL without query arguments or page number
*
* @since 5.4.0
*
* @return string The clean URL.
*/
function fictioneer_get_clean_url() {
global $wp;
// Setup
$url = home_url( $wp->request );
// Remove page (if any)
$url = preg_replace( '/\/page\/\d+\/$/', '', $url );
$url = preg_replace( '/\/page\/\d+$/', '', $url );
// Return cleaned URL
return $url;
}
}
?>

View File

@ -213,10 +213,7 @@ add_action( 'fictioneer_header', 'fictioneer_header_background', 10 );
function fictioneer_sort_order_filter_interface( $args ) {
// Setup
$base_uri = strtok( $_SERVER['REQUEST_URI'], '?' );
$current_url = home_url( $base_uri );
$current_url = preg_replace( '/\/page\/\d+\/$/', '', $current_url );
$current_url = preg_replace( '/\/page\/\d+$/', '', $current_url );
$current_url = fictioneer_get_clean_url();
$post_type = null;
// Archive?