Support » Developing with WordPress » “Better control of the `redirect_guess_404_permalink()` function”… how?

  • WordPress 5.5 promises “Better control of the redirect_guess_404_permalink() function”. I’ve searched for help on how to achieve that but am coming up empty. Can anyone help?

    Here’s a simple example…

    On a site with 1,500 blog posts, it was decided to change a few hundred old posts into a custom post type of “News Items”.

    Old post URLs were, for example:

    and are now:

    WordPress now guesses (badly) and returns the wrong item. Is there a way for me to use the redirect_guess_404_permalink() function (or something else?) to intercept these now-broken URLs and redirect them automatically to the new ones?

    The logic would be…

    if /blog/2010/01/01/title-of-post doesn’t exist…
    if /news/2010/01/01/title-of-post exists, redirect to it; otherwise…

    Any suggestions appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    You can use the ‘pre_redirect_guess_404_permalink’ filter to implement any desired logic you want. If your callback returns a correct URL, that will be the one used. Return false to generate a 404 response. You can return null to let WP do its default redirect guessing.

    Thread Starter hommealone


    Thanks @bcworkz

    That points me in the right direction. I found the documentation of that hook here but the details are still a little thin. No user notes there yet on that filter hook page. I’ve asked Prof. Google for explanations of how to use pre_redirect_guess_404_permalink but I’m still coming up empty-handed.

    If anyone could supply any user notes about “tips, explanations, use-cases, [or] best practices” or examples, that would be much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.