0

Can you help me this time to fix this problem

my code is:

public function numeric_pagination() {
        global  $wp_query , $wp_rewrite;;
        if ( $wp_query->max_num_pages < 2 ) {
            return;
        }
        $paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
        $pagenum_link = html_entity_decode( get_pagenum_link() );
        $total        = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
        $url_parts    = explode( '?', $pagenum_link );
        $pagenum_link = trailingslashit( $url_parts[0] ) . '%_%';
        $format       = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
        $format      .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
        $links = paginate_links( array(
            'base'     => $pagenum_link,
            'format'   => $format,
            'total'    => $wp_query->max_num_pages,
            'current'  => $paged,
            'total'    => $total,
            'mid_size' => 1,
            'prev_text' => '«',
            'next_text' => '»',
            'type'      => 'array',
        ) );
        if( is_array( $links ) ) {
            $pagination  = '<div class="pagination-wrap"><ol class="pagination">';
            foreach ( $links as $page_key => $page) {
                $pagination .= "<li>$page</li>";
            }
            $pagination .= '</ol></div>';
            return $pagination;
        }
        return false;
    }

and my problem is At the end the category main page link gives a "/" which causes redirection 301

example: mysite.com/category/ -> redirect to mysite.com/category

i need remove / in category main page

The rest of the pages are correct example: mysite.com/category/page/2

mysite.com/category/page/3

1 Answer 1

0

You can remove the trailing slash from the pagination links by adding untrailingslashit() function as callback for paginate_links filter.

Put this code in your theme's functions.php or in an mu-plugin (untested):

add_filter( 'paginate_links', 'untrailingslashit' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.