[wp-trac] [WordPress Trac] #52998: Add a filter to paginate_links to allow bypassing merging query params
WordPress Trac
noreply at wordpress.org
Thu Apr 8 10:36:11 UTC 2021
#52998: Add a filter to paginate_links to allow bypassing merging query params
----------------------------+-----------------------------
Reporter: jonoaldersonwp | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords: seo
Focuses: performance |
----------------------------+-----------------------------
The [https://core.trac.wordpress.org/browser/tags/5.7/src/wp-includes
/general-template.php#L4154 paginate_links] function constructs the HTML
markup used in archive pagination.
As part of this, any parameters present in the requesting URL are merged
into the pagination links
([https://core.trac.wordpress.org/browser/tags/5.7/src/wp-includes
/general-template.php#L4197 ref]).
This is a safeguard to ensure that any logic which relies on `$_GET`
parameters in a paginated series still functions as expected as the user
navigates through paginated states. E.g., a plugin may use query
parameters to describe a date range in an archive; such as
`/archive/page/2/?date_from=2001-12-20&date_to=2020-05-14`.
I'd like for theme/plugin authors to be able to disable/bypass this
'merging' process.
**The problem(s)**
The current behaviour makes it possible to request (paginated) archive
templates with arbitrary, meaningless query parameters (e.g.,
https://wordpress.org/support/topic-
tag/iframe/page/5/?cats=yes&dogs=no&cake=please&utm_tracking=broken).
Those parameters persist through all subsequent paginated requests.
This bypasses caches, breaks digital analytics, and inflates crawling from
third party systems (search engines, social media, etc), as it 'creates'
many additional URLs.
Furthermore, because WordPress doesn't natively output canonical URL tags
on paginated archives, this can be ''extremely'' destructive from an SEO
perspective; particularly on large sites, where the 'existence' of many
such URLs compounds the problems above. And whilst the presence of a
canonical tag would mitigate ''some'' of that damage, it wouldn't address
those other problems.
**A potential solution**
I propose that we should introduce a new filter into
[https://github.com/WordPress/WordPress/blob/master/wp-includes/general-
template.php#L4154 paginate_links] which allows theme/plugin authors to
bypass the code block which merges in query parameters.
The filter should accept a simple boolean value, which acts as a switch to
skip the merging logic.
** A note on the existing `paginate_links` filter**
Note that [https://github.com/WordPress/WordPress/blob/master/wp-includes
/general-template.php#L4302 a paginate_links filter already exists] at the
end of the function, but this only allows for manipulating the `href`
attribute of the link. Whilst this could ''technically'' be used to
''strip'' parameters via brute force, this is cumbersome, and requires
knowledge of the correct canonical URL (which WordPress doesn't
natively/reliably have).
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52998>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list