Opened 6 months ago
Paginate links' "base" default value causes page 2 to display links incorrectly.
|Reported by:||Nessworthy||Owned by:|
Let's say if I called the following:
echo paginate_links( array( 'current' => $current_page, // must be 2 to replicate 'total' => $total_pages, // e.g. 5 ) );
The following results in 'previous' and '1' page links becoming equal to the current URL. This means that if 'current' is being taken from the URL directly, the two links will always be equal to the second page.
Dissecting the source general-template.php:1922 , I can see that there is a check in the code where, if the current page is 2, it changes how the link is displayed. Here's the line:
$link = str_replace('%_%', 2 == $current ? '' : $format, $base);
So, using the default settings and setting the current page as two,
$link becomes an empty string.
This is because the default ('%_%') is being replaced by an empty string instead of $format .
Because link then doesn't contain the placeholder needed to show the intended page number, it remains empty when the next line is ran:
$link = str_replace('%#%', $current - 1, $link);
If no additional data is appended via. add args / add fragment, the string remains empty at the time of output, which browsers then default it to the current page URL.