Opened 9 years ago
Closed 8 years ago
#36168 closed enhancement (fixed)
Introduce get_canonical_url function
Reported by: | joostdevalk | Owned by: | ocean90 |
---|---|---|---|
Milestone: | 4.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Canonical | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Short version
We need a function that allows consistent retrieving and filtering of the canonical URL. I'm proposing creating a get_canonical_url
function to do just that.
Explanation
With the advent of more and more different ways to deliver content, we need to make sure the canonical URL on all these different manifestations of content is correct. Right now, all the plugins out there, for instance the AMP plugin here, the the Instant Articles plugin here and core's own post oEmbed functionality, all in some way use get_permalink
to get the canonical. The point of a canonical URL is that it can point to the canonical version and that this does not necessarily have to be the representation in the WP database. Thus you need to be able to filter it.
I'm attaching a patch that introduces get_canonical_url
and uses this in core's rel_canonical
function, which is used on both the normal output of posts and pages as well as on oEmbed iframes.
Attachments (4)
Change History (20)
#1
@
9 years ago
- Owner set to joostdevalk
- Status changed from new to assigned
- Summary changed from Introduce get_canonical function to Introduce get_canonical_url function
#3
@
9 years ago
There are quite a few plugins out there that modify the permalink, e.g. analytics-plugins that add tracking codes to the URL to let publishers know that the visitor came via a feed.
But in some instances, like with the Instant Articles plugin mentioned in the ticket explanation, it is critical to get a clean canonical URL. A get_canonical_url()
would be very useful, so we can be assured that we provide the actual canonical URL and not some permalink that has been tampered with.
I’m very much +1 on this.
#5
follow-up:
↓ 6
@
9 years ago
So the main difference is that this integrates post paging and comments paging?
#6
in reply to:
↑ 5
@
9 years ago
Replying to markjaquith:
So the main difference is that this integrates post paging and comments paging?
No, that code was there already, just got moved as otherwise this wouldn't work. I'd say the main difference is that we have a specific function and filter for the canonical, because it's conceptually different from the rather generic get_permalink
.
#7
follow-up:
↓ 8
@
9 years ago
This may also be a good place to enforce a canonical scheme for sites. Related: #30581
#9
@
9 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
Bit unsure what name to give the test file, so if there is a better name or place for it please let me know.
This ticket was mentioned in Slack in #core by chriscct7. View the logs.
8 years ago
#12
@
8 years ago
- Keywords dev-feedback 4.6-early removed
- Owner changed from joostdevalk to ocean90
- Status changed from assigned to reviewing
This ticket was mentioned in Slack in #core by voldemortensen. View the logs.
8 years ago
#14
@
8 years ago
@joostdevalk, @jipmoors: Thanks for your patches. 36168.patch is a refresh and includes following changes:
- Name of function should start with
wp_
:wp_get_canonical_url()
- Removes the default argument for
get_permalink()
- Docs tweaks
- Tests: Use shared test fixture
- Tests: Use
WP_UnitTestCase::go_to()
andWP_UnitTestCase::set_permalink_structure()
- Tests: Move test class to the /link/ directory
Let me know what you think.
#15
@
8 years ago
36168.diff improves 36168.patch by adding a changelog entry to the DocBlock for rel_canonical()
and other minor docs tweaks.
First patch