Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#50084 new defect (bug)

redirect_canonical() need additional hook

Reported by: tkama's profile Tkama Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Canonical Keywords:
Focuses: Cc:

Description

There is no hook in [redirect_canonical()](https://wp-kama.ru/filecode/wp-includes/canonical.php#L12-625) function that allow as to extend it's logic.

For example, I have the following permastructure /%post_id%/%post_name%. And I can visit the post by such URL /123. But I need the redirect to right URL /123/postname.

And if I try to use the redirect_canonical hook to fix this BUG, the hook won't work, because it's too late and the hook is never triggers.

At the bottom of the function [we have such code](https://wp-kama.ru/filecode/wp-includes/canonical.php#L572-605):

<?php
        if ( ! $redirect_url || $redirect_url == $requested_url ) {
                return;
        }

...
        $redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url );

Why there is no hook before return? Hook that allows us set our own $redirect_url...

Change History (3)

#1 in reply to: ↑ description @SergeyBiryukov
5 years ago

Hi there, welcome back to WordPress Trac! Thanks for the report.

For example, I have the following permastructure /%post_id%/%post_name%. And I can visit the post by such URL /123. But I need the redirect to right URL /123/postname.

Just noting this was previously reported in #12456.

If a new hook is intended as a workaround for this particular issue, it seems better to just fix the issue instead.

#2 @Tkama
5 years ago

I talking about not only one issue - it's just example. I try to say that there is no hook in the redirect_canonical() function that allow to extend the function.

I try to extend, but redirect_canonical not work. I explained why above.

#3 @SergeyBiryukov
5 years ago

  • Component changed from General to Canonical
Note: See TracTickets for help on using tickets.