wp_old_slug_redirect()
Redirect old slugs to the correct permalink.
Attempts to find the current slug from the past slugs.
1 time — 0.000717 sec (slow) | 50000 times — 21.05 sec (slow) | PHP 7.2.5, WP 4.9.8
Hooks from the function
Return
null
. Nothing.
Usage
wp_old_slug_redirect();
Examples
#1 Disable redirection from old slugs (post_names)
By default, when visiting each individual non-hierarchical post, WP makes a query to the database and checks all _wp_old_slug
meta-fields of all posts to see if there is a shortcut from the current query. If such a meta-field is found, the current request is considered as the old URL of the post, so a redirect to the new URL of the posts is made.
If you don't need this behavior (not recommended), you can disable such redirections (checks) like so:
remove_action( 'template_redirect', 'wp_old_slug_redirect' );
For the query, see function _find_post_by_old_slug().
Changelog
Since 2.1.0 | Introduced. |