Every WordPress post has its on slug, which is automatically generated by your post’s title. If you decide to change the post slug later, WordPress will remember the old one and redirect it to the new one. It’s possible to prevent old post slug redirection in WordPress by adding removing a couple of actions from your WordPress core with a small snippet.
Just add following code to your current theme’s functions.php file to prevent WordPress from redirecting old post slugs to new ones:
remove_action( 'template_redirect', 'wp_old_slug_redirect' ); remove_action( 'post_updated', 'wp_check_for_changed_slugs', 12, 3 );
Plus, you can also remove all the old post slugs from your WordPress’ MySQL by running following code to your theme’s functions.php file:
[alert style=”red”]Note: Please remove this code immediately after saving your functions.php file. You only need to run this code once, there’s no need to keep this code in your theme.[/alert]
$wpdb->query( " DELETE FROM $wpdb->postmeta WHERE meta_key = '_wp_old_slug' " );