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/ 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. 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

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():

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

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.

#5-5, #dev-notes, #permalinks

Trying to decide what to do with comment …

Trying to decide what to do with comment permalinks when paging is turned on.

#comments, #permalinks

Permalinks with the structure /index.php …

Permalinks with the structure /index.php/%postname%/ (or the same, without the trailing slash) now work. And now the tagtag A directory in Subversion. WordPress uses tags to store a single snapshot of a version (3.6, 3.6.1, etc.), the common convention of tags in version control systems. (Not to be confused with post tags.)/categoryCategory The 'category' taxonomy lets you group posts / content together that share a common bond. Categories are pre-defined and broad ranging. bases are normalized to have no leading/trailing slash, so it’ll just be topics or tagged for example.

#bugs, #categories, #permalinks, #tags

Fixed an ugly bug that broke page links …

Fixed an ugly bugbug A bug is an error or unexpected result. Performance improvements, code optimization, and are considered enhancements, not defects. After feature freeze, only bugs are dealt with, with regressions (adverse changes from the previous version) being the highest priority. that broke page links for setups that use PATH_INFO permalinks with %categoryCategory The 'category' taxonomy lets you group posts / content together that share a common bond. Categories are pre-defined and broad ranging.% at the beginning of the permalink structure.

#bugs, #permalinks