2 ? array_pop( $parts ) : ''; $url = join( '?', $parts ); $url = preg_replace( '#(.+?)(/\?|\?)(.*?)(/.+?$)$#', '$1$4$5?$3', $url ); $url = preg_replace( '#(\?.+)(%2F|\/)$#', '$1', $url ); if ( '' !== $last_part && strpos( $url, '?' . $last_part ) === false ) { $url .= '&' . $last_part; } $parts = explode( '?', $url ); if ( isset( $parts[1] ) ) { // Maybe remove duplicated lang param $params = array(); parse_str( $parts[1], $params ); $url = $parts[0] . '?' . build_query( $params ); } return $url; } /** * Filters the pagination links on paginated posts and pages, acting on the links html * output containing the anchor tag the link is a property of. * * @param string $link_html * * @return string * * @hook wp_link_pages_link */ public function paginated_link_filter( $link_html ) { return preg_replace( '#"([^"].+?)(/\?|\?)([^/]+)(/[^"]+)"#', '"$1$4?$3"', $link_html ); } }