Should i remove all of this and replace it by that single line?
$index = $_SERVER[‘PHP_SELF’];
$index = preg_replace(‘|^’. $home_root . ‘|’, ”, $index);
$index = preg_replace(‘|^/+|’, ”, $index);
// if we already have a QUERY style page string
if ( stristr( $qstr, $page_querystring ) ) {
$replacement = “$page_querystring=$pagenum”;
$qstr = preg_replace(“/”.$page_querystring.”[^\d]+\d+/”, $replacement, $qstr);
// if we already have a mod_rewrite style page string
} elseif ( preg_match( ‘|’.$page_modregex.’\d+|’, $qstr ) ) {
$permalink = 1;
$qstr = preg_replace(‘|’.$page_modregex.’\d+|’,”$page_modstring$pagenum”,$qstr);
// if we don’t have a page string at all …
// lets see what sort of URL we have…
} else {
// we need to know the way queries are being written
// if there’s a querystring_start (a “?” usually), it’s definitely not mod_rewritten
if ( stristr( $qstr, ‘?’ ) ) {
// so append the query string (using &, since we already have ?)
$qstr .= ‘&’ . $page_querystring . ‘=’ . $pagenum;
// otherwise, it could be rewritten, OR just the default index …
} elseif( ” != get_settings(‘permalink_structure’) && ! is_admin() ) {
$permalink = 1;
$index = $wp_rewrite->index;
// If it’s not a path info permalink structure, trim the index.
if ( !$wp_rewrite->using_index_permalinks() ) {
$qstr = preg_replace(“#/*” . $index . “/*#”, ‘/’, $qstr);
} else {
// If using path info style permalinks, make sure the index is in
// the URI.
if ( strpos($qstr, $index) === false )
$qstr = ‘/’ . $index . $qstr;
}
$qstr = trailingslashit($qstr) . $page_modstring . $pagenum;
} else {
$qstr = $index . ‘?’ . $page_querystring . ‘=’ . $pagenum;
}
}
$qstr = preg_replace(‘|^/+|’, ”, $qstr);
if ( $permalink )
$qstr = trailingslashit($qstr);
$qstr = preg_replace(‘/&([^#])(?![a-z]{1,8};)/’, ‘&$1’, trailingslashit( get_settings(‘home’) ) . $qstr );
// showing /page/1/ or ?paged=1 is redundant
if ( 1 === $pagenum ) {
$qstr = str_replace(‘page/1/’, ”, $qstr); // for mod_rewrite style
$qstr = remove_query_arg(‘paged’, $qstr); // for query style
}
return $qstr;
}