Make WordPress Core

Opened 14 years ago

Closed 10 years ago

#14458 closed enhancement (duplicate)

Create rel_canonical filter

Reported by: wjm's profile wjm Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Canonical Keywords: has-patch
Focuses: Cc:


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.


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 14 years ago.

Download all attachments as: .zip

Change History (7)

#1 @nacin
14 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.

#2 @husobj
13 years ago

  • Cc ben@… added


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?

#3 @here
11 years ago

  • Cc mike@… added

see also #18660

#4 @joostdevalk
11 years ago

So, almost every theme and or plugin now unhooks this function and then adds their own function. This causes multiple canonicals to be on page every once in a while, so I'd *really* appreciate this filter :) (the patch still works other than the fact that the line number changed).

#5 @joostdevalk
11 years ago

Related to #18660 as well by the way.

#6 @ocean90
10 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#18660 covers this as well.

Note: See TracTickets for help on using tickets.