0

I am using the paginate_links function in a custom theme to generate the pagination links which is working fine however the page 1 link which is /blog/page/1 gets a 301 redirect to /blog/.

This is the same content and page so is fine but it seems like an unnecessary redirect so I was trying to find a way to change the page 1 link to just to be /blog/.

I've had a search around and feel like something could be done in the base variable rather than putting in custom pagination but of the things I've tried it breaks the pagination.

$current = max( 1, get_query_var('paged') );    
$big = 999999999;
        echo paginate_links( 
          [
              'base'         => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
              'total'        => $update->max_num_pages,
              'current'      => $current,
              'format'       => '/blog/page/%#%',
              'show_all'     => false,
              'type'         => 'plain',
              'end_size'     => 4,
              'mid_size'     => 1,
              'prev_next'    => true,
              'prev_text'    => '<i class="fas fa-arrow-left"></i>',
              'next_text'    => '<i class="fas fa-arrow-right"></i>',
              'add_args'     => false,
              'add_fragment' => '',
          ]
        );
  • Is /blog not going to show the first page anyway? Pagination starts at 1 not 0, the first page is 1, the second page is 2, etc, there is no "not on a page" state, so loading /blog would give you exactly the same content as /blog/page/1, so it redirects to prevent duplication – Tom J Nowell Jan 9 '20 at 16:14
  • 1
    Yes, that's correct but it's the redirect that I'm trying to avoid as it's not necessary. The page 1 link should just be /blog/ rather than being /blog/page/1 and then redirecting. – user1085987 Jan 9 '20 at 16:35
  • I was passed the below link by someone else which had the solution: stackoverflow.com/questions/46195352/… – user1085987 Jan 10 '20 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.