10

On one of my pages I changed the slug to form a different URL. E.g.

Old: http://example.com/old-slug

New: http://example.com/new-slug

WordPress has done it's thing of redirecting http://example.com/old-slug to http://example.com/new-slug.

I'd like to remove this behaviour as a plugin I am using makes use of the slug in question and the redirect overrides its behaviour.

I checked this question, and checked my wp_postmeta table for instances of _wp_old_slug but nothing is returned. My server is Nginx so shouldn't be affected by .htaccess files.

Is there anything else I can do to remove this redirect?

1
  • 2
    It seems odd that your wp_postmeta table wouldn't have any _wp_old_slug keys - the bit of code that does that is in wp-includes/query.php (wp_old_slug_redirect()) - you could add an exit or debug statement there to check if it's being called. Also, remember that if WordPress can't find a permalink, it looks posts which match the start, e.g. if you had a post called /foobar, then /foo will redirect to it. Commented Apr 8, 2015 at 14:11

5 Answers 5

7

This (in your functions.php) will turn it off (but see also the comment I've left):

remove_action('template_redirect', 'wp_old_slug_redirect');

It seems odd that your wp_postmeta table wouldn't have any _wp_old_slug keys - the bit of code that does that is in wp-includes/query.php (wp_old_slug_redirect()) - you could add an exit or debug statement there to check if it's being called.

Also, remember that if WordPress can't find a permalink, it looks for posts with a matching beginning, e.g. if you had a post with permalink /foobar, then /foo will redirect to it.

3
  • 1
    Could you add your comment into the answer just to flesh it out and have all the content in one place?
    – Howdy_McGee
    Commented Apr 8, 2015 at 14:16
  • Indeed, your comment was the solution. I have a page called Events which had the slug events-page. No page had the slug events but when visiting example.com/events it redirected to the Events page. WP was obviously matching the slug to a page with the same title as nothing else existed for it.
    – harryg
    Commented Apr 8, 2015 at 15:21
  • 1
    didnt work for me
    – zEn feeLo
    Commented Apr 2, 2019 at 17:15
3

this worked for me:

   remove_filter('template_redirect', 'redirect_canonical');  

source: http://biostall.com/prevent-wordpress-redirecting-to-nearest-matching-url/

2
  • didnt work for me
    – zEn feeLo
    Commented Apr 2, 2019 at 17:15
  • 1
    Astounding that WP would have this enabled by default
    – 111
    Commented Feb 23, 2020 at 22:40
1

To manually remove automatic redirects after slug change, just delete the corresponding rows from the "wp-redirection-items" from the database using phpMyAdmin.

This is the best and simplest way which allows you to remove redirects for specific posts. More details can be found here http://couponnexus.com/remove-wordpress-redirects-changing-slug/

3
  • How do you know the OP is using exactly that plugin?
    – fuxia
    Commented Mar 2, 2017 at 13:57
  • 1
    your link doesnt work
    – zEn feeLo
    Commented Apr 2, 2019 at 17:16
  • There doesn't seem to be a table named wp-redirection-items
    – Flimm
    Commented May 20 at 12:23
0

What helped for was permalinks reset. just go to Settings -> Permalinks, pick default, hit Save Changes. Then pick your structure and hit Save Changes again.

2
  • 2
    doesnt workkkkk
    – zEn feeLo
    Commented Apr 2, 2019 at 17:13
  • This did the trick for me! Thanks. Commented Apr 4, 2022 at 19:05
0

Every WordPress post has its own 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 );
2
  • how does it affect SEO?
    – zEn feeLo
    Commented Apr 2, 2019 at 16:54
  • I added these lines, It doesnt work
    – zEn feeLo
    Commented Apr 2, 2019 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.