You can do a simple str_replace( '/page/1/', "https://wordpress.stackexchange.com/", $string )
on the results generated by paginate_links()
to get rid of /page/1/
which appears on the first page link as well as the Prev link (when it points to the first page).
Here’s a full (tested) example:
/**
* Numeric pagination via WP core function paginate_links().
* @link http://codex.wordpress.org/Function_Reference/paginate_links
*
* @param array $srgs
*
* @return string HTML for numneric pagination
*/
function wpse_pagination( $args = array() ) {
global $wp_query;
if ( $wp_query->max_num_pages <= 1 ) {
return;
}
$pagination_args = array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $wp_query->max_num_pages,
'current' => max( 1, get_query_var( 'paged' ) ),
'format' => '?paged=%#%',
'show_all' => false,
'type' => 'array',
'end_size' => 2,
'mid_size' => 3,
'prev_next' => true,
'prev_text' => __( '« Prev', 'wpse' ),
'next_text' => __( 'Next »', 'wpse' ),
'add_args' => false,
'add_fragment' => '',
// Custom arguments not part of WP core:
'show_page_position' => false, // Optionally allows the "Page X of XX" HTML to be displayed.
);
$pagination = paginate_links( array_merge( $pagination_args, $args ) );
// Remove /page/1/ from links.
$pagination = array_map(
function( $string ) {
return str_replace( '/page/1/', "https://wordpress.stackexchange.com/", $string );
},
$pagination
);
return implode( '', $pagination );
}
Usage:
echo wpse_pagination();