3

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
    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. – William Turrell Apr 8 '15 at 14:11
5

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.

  • 1
    Could you add your comment into the answer just to flesh it out and have all the content in one place? – Howdy_McGee Apr 8 '15 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 Apr 8 '15 at 15:21
  • didnt work for me – Cameron A Apr 2 at 17:15
2

this worked for me:

   remove_filter('template_redirect', 'redirect_canonical');  

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

  • didnt work for me – Cameron A Apr 2 at 17:15
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.

  • doesnt workkkkk – Cameron A Apr 2 at 17:13
0

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/

  • How do you know the OP is using exactly that plugin? – fuxia Mar 2 '17 at 13:57
  • your link doesnt work – Cameron A Apr 2 at 17:16
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 );
  • how does it affect SEO? – Cameron A Apr 2 at 16:54
  • I added these lines, It doesnt work – Cameron A Apr 2 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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