How to disable redirect on pagination first page

Question

When I pagin to my.site/mypage/page/1 its redirect me to my.site/mypage/,
i try to disable it on (template_redirect, do_redirect_guess_404_permalink, redirect_canonical) hooks but it not help

here is my pagin function

function my_custom_pagination($total_page) {
    global $wp_query;
     // need an unlikely integer
    $url = preg_replace('/?.*/', '/', get_pagenum_link(1));
    $url = preg_replace('/(/amp)/', '', $url);
    if (get_query_var('paged')) {
        $paged = get_query_var('paged');
    } elseif (get_query_var('page')) {
        $paged = get_query_var('page');
    } else {
        $paged = 1;
    }
    $pages = paginate_links( array(
        'base' => $url . '%_%',
        'format' => 'page/%#%/',
        'current' => max( 1, $paged),
        'total' => $total_page,
        'prev_next' => false,
        'type'  => 'array',
        'end_size' => 1,
        'mid_size' => 3,
        'prev_text'    => '',
        'next_text'    => '',
    ) );
    
    $output = '';

    if ( is_array( $pages ) ) {
        $output .=  '<ul class="pagination-list">';
        foreach ( $pages as $page ) {
            $output .= "<li class='pagination-item' >$page</li>";
        }
        $output .= '</ul>';
    
    }

    return $output;
}
0
Eugenicus 2 months 0 Answers 8 views 0

Leave an answer