Skip to main content
4 of 11
added 149 characters in body
birgire
  • 67.8k
  • 7
  • 119
  • 251

I took a look at the paginate_links() source code (v3.5.1) and there is this line (#)

$link = str_replace('%_%', 1 == $n ? '' : $format, $base);

that is giving you the empty string for the n=1 page.

With your setup you have $base = "%_%" and $format = "http://example.com/page/%#%/" so this becomes:

$link = str_replace('%_%', 1 == $n ? '' : "http://example.com/page/%#%/", "%_%");

where we have 2 cases:

n=1:     $link = str_replace('%_%', '', "%_%");

n>1:     $link = str_replace('%_%', "http://example.com/page/%#%/", "%_%");

and after the replace:

n=1:     $link = '';

n>1:     $link = "http://example.com/page/%#%/";

Here is an example of the output from paginate_links():

<ul class='page-numbers'>
    <li><a class="prev page-numbers" href="http://example.com/page/2/">&laquo; Previous</a></li>
    <li><a class='page-numbers' href=''>1</a></li>
    <li><a class='page-numbers' href='http://example.com/page/2/'>2</a></li>
    <li><span class='page-numbers current'>3</span></li>
    <li><a class='page-numbers' href='http://example.com/page/4/'>4</a></li>
    <li><a class='page-numbers' href='http://example.com/page/5/'>5</a></li>
    <li><a class='page-numbers' href='http://example.com/page/6/'>6</a></li>
    <li><a class="next page-numbers" href="http://example.com/page/4/">Next &raquo;</a></li>
</ul>

If you use instead (#):

'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',

you will get a non empty homelink and the the output of paginate_links() would be something like:

<ul class='page-numbers'>
    <li><a class="prev page-numbers" href="http://example.com/page/2/">&laquo; Previous</a></li>
    <li><a class='page-numbers' href='http://example.com/page/1/'>1</a></li>
    <li><a class='page-numbers' href='http://example.com/page/2/'>2</a></li>
    <li><span class='page-numbers current'>3</span></li>
    <li><a class='page-numbers' href='http://example.com/page/4/'>4</a></li>
    <li><a class='page-numbers' href='http://example.com/page/5/'>5</a></li>
    <li><a class='page-numbers' href='http://example.com/page/6/'>6</a></li>
    <li><a class="next page-numbers" href="http://example.com/page/4/">Next &raquo;</a></li>
</ul>
birgire
  • 67.8k
  • 7
  • 119
  • 251