Title: WordPress 5.5: Better fine grained control of redirect_guess_404_permalink()
Author: Jb Audras
Published: June 26, 2020

---

 [  ](https://profiles.wordpress.org/audrasjb/) [Jb Audras](https://profiles.wordpress.org/audrasjb/)
9:06 pm _on_ June 26, 2020     
Tags: [5.5 ( 87 )](https://make.wordpress.org/core/tag/5-5/),
[dev-notes ( 647 )](https://make.wordpress.org/core/tag/dev-notes/), [permalinks ( 4 )](https://make.wordpress.org/core/tag/permalinks/)

# WordPress 5.5: Better fine grained control of redirect_guess_404_permalink()

Since WordPress 2.3.0, the `redirect_guess_404_permalink()` function has existed
to attempt guessing the desired URLURL A specific web address of a website or web
page on the Internet, such as a website’s URL www.wordpress.org based on the query
variables available. This is especially useful when a post’s parent changes (for
hierarchical post types), or a post’s slug is changed.

Guessing a URL to redirect 404 requests is fine for the majority of WordPress sites,
but site owners, developers, and pluginPlugin A plugin is a piece of software containing
a group of functions that can be added to a WordPress website. They can extend functionality
or add new features to your WordPress websites. WordPress plugins are written in
the PHP programming language and integrate seamlessly with WordPress. These can 
be free in the WordPress.org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
or can be cost-based plugin from a third-party. authors may want more fine grained
control over the guessing logic.

This is a long-standing issue, as the original ticketticket Created for both bug
reports and feature development on the bug tracker. was opened 9 years ago. So long,
WordPress 5.5 will add the ability to manage that feature properly.

## Short-circuiting default guessing logic

The new `pre_redirect_guess_404_permalink` filterFilter Filters are one of the two
types of Hooks [https://codex.wordpress.org/Plugin_API/Hooks](https://codex.wordpress.org/Plugin_API/Hooks).
They provide a way for functions to modify data of other functions. They are the
counterpart to Actions. Unlike Actions, filters are meant to work in an isolated
manner, and should never have side effects such as affecting global variables and
output. can now be used to short-circuit the function, bypassing the default guessing
logic. This is useful to execute custom logic that better fits each individual site’s
needs to make a more accurate guesses.

Returning a non-false value to the filter will cause the function to return the 
filtered value early.

### Example

    ```notranslate
    function mysite_pre_redirect_guess_404_permalink() {
        // Custom redirect URL guessing logic.
       return $new_redirect_url;
    }
    add_filter( 'pre_redirect_guess_404_permalink', 'mysite_pre_redirect_guess_404_permalink' );
    ```

## Controlling “strict” vs. “loose” comparison

The `strict_redirect_guess_404_permalink` can now be used to filter whether a “strict”
or “loose” comparison is used to make a redirect URL guess.

**“Strict” comparisons** (`true`) will make a guess suggestion for a redirect only
when exact `post_name` matches are found.

**“Loose” comparisons **(`false`) is the default option and will perform a `LIKE`
query on `post_name`.

### Example

The following example will enable “strict” comparisons in `redirect_guess_404_permalink()`:

    ```notranslate
    add_filter( 'strict_redirect_guess_404_permalink', '__return_true' );
    ```

## Disable 404 redirect guessing

The `do_redirect_guess_404_permalink` filter can now be used to completely disable
redirect guessing. Returning `false` to the filter will disable the feature entirely.

### Example

    ```notranslate
    add_filter( 'do_redirect_guess_404_permalink', '__return_false' );
    ```

---

For more information on these changes, consult the related TracTrac An open source
project by Edgewall Software that serves as a bug tracker and project management
tool for WordPress. ticket: [#16557](https://core.trac.wordpress.org/ticket/16557).

[#5-5](https://make.wordpress.org/core/tag/5-5/), [#dev-notes](https://make.wordpress.org/core/tag/dev-notes/),
[#permalinks](https://make.wordpress.org/core/tag/permalinks/)

### Share this:

 * [  Threads ](https://make.wordpress.org/core/2020/06/26/wordpress-5-5-better-fine-grained-control-of-redirect_guess_404_permalink/?share=threads)
 * [  Mastodon ](https://make.wordpress.org/core/2020/06/26/wordpress-5-5-better-fine-grained-control-of-redirect_guess_404_permalink/?share=mastodon)
 * [  Bluesky ](https://make.wordpress.org/core/2020/06/26/wordpress-5-5-better-fine-grained-control-of-redirect_guess_404_permalink/?share=bluesky)
 * [  X ](https://make.wordpress.org/core/2020/06/26/wordpress-5-5-better-fine-grained-control-of-redirect_guess_404_permalink/?share=x)
 * [  Facebook ](https://make.wordpress.org/core/2020/06/26/wordpress-5-5-better-fine-grained-control-of-redirect_guess_404_permalink/?share=facebook)
 * [  LinkedIn ](https://make.wordpress.org/core/2020/06/26/wordpress-5-5-better-fine-grained-control-of-redirect_guess_404_permalink/?share=linkedin)

 1. ![](https://secure.gravatar.com/avatar/86b8ed1647235e5d3657fc26e8cc5b85b2fa5bb073484d0375968d2aa026385e?
    s=32&d=mm&r=g)
 2.  [devrekli](https://profiles.wordpress.org/devrekli/)  12:53 am _on_ June 28, 2020
 3. you can help me? thanks
 4. [https://core.trac.wordpress.org/ticket/50490](https://core.trac.wordpress.org/ticket/50490)
 5.  I tried this but these did not solve the problem
 6.     ```notranslate
        add_filter( 'do_redirect_guess_404_permalink', '__return_false' );
        ```
    

Comments are closed.

# Post navigation

[← Media Meeting Recap – June 25, 2020](https://make.wordpress.org/core/2020/06/26/media-meeting-recap-june-25-2020/)

[Editor Chat Agenda: 1st July, 2020 →](https://make.wordpress.org/core/2020/06/29/editor-chat-agenda-1st-july-2020/)