Opened 3 years ago

Last modified 2 years ago

#14458 new enhancement

Create rel_canonical filter

Reported by: wjm Owned by:
Priority: normal Milestone: Future Release
Component: Canonical Version: 3.0
Severity: normal Keywords: has-patch
Cc: ben@…

Description

Wouldn't it be nice to be able to set the canonical rel value.
This comes in handy when you create a duplicate page and be able to manipulate the cannonical value.

Usage:

add_filter( 'rel_canonical', 'childtheme_rel_canonical', 10, 2 );
function childtheme_rel_canonical( $link, $id ) {
  return get_permalink( 55 );
}

Attachments (1)

rel_canonical_filter.patch (396 bytes) - added by wjm 3 years ago.

Download all attachments as: .zip

Change History (3)

wjm3 years ago

  • Milestone changed from Awaiting Review to Future Release

Not convinced this is necessary. Filters are already there for this in get_permalink(), and you could also unhook canonical and do it yourself for that page.

  • Cc ben@… added

@nacin

True, you could unhook canonical and do it yourself, but that isn't as robust as a filter.
Consider the following scenario.

If I use an SEO plugin, they will often unhook this and provide their own canonical implementation.

Now if I have a plugin installed that provides fairly complex functionality. For example, e-commerce, where you have products which would exist in multiple taxonomies under different URL paths. It is likely for such a plugin that it would want to override the canonical implementation to ensure that the most relevent URL is used as the canonical link for a product.

At this point the e-commerce plugin wouldn't necessarily know where an SEO had unhooked canonical and implemented it's own thing so you can't do anything about it. At this point it would be more helpful if canonical was a filter so that SEO plugins could filter it, then if another plugin wants to override if could apply a filter at a higher priority to override it.

Then say I create I create a plugin to add extra functionality to the e-commerce plugin and want to override their canonical functionality, I can override their filter.

I guess because the outcome of canonical should be a single value/output it should be a case of whichever plugin "shouts loudest wins" which is probably best achieve using a filter?

Note: See TracTickets for help on using tickets.