I need to use javascript redirection in one of my scripts. With /%postname%/ WP permalinks structure redirection works like it should but with default it always redirects to home page.

/%postname%/ structure script:


default permalinks structure script:

  • Does the page load properly when you put http://www.url.com/?customposttype=postslug into your browser? – random_user_name Mar 18 '14 at 20:13
  • Yes it loads normaly – raaaa Mar 18 '14 at 20:16
  • But when the script runs on the page, you are saying to loads the home page? Does the actual correct URL show up in the browser url bar, or does it just load the home page directly? – random_user_name Mar 18 '14 at 21:44
  • Correct URL shows but it loads home page – raaaa Mar 18 '14 at 21:54
  • Check the browser title bar - are you sure it's not loading a 404 / Page not found? – random_user_name Mar 18 '14 at 22:49

The issue is that your script is doing a replace, but really what you want is to set the window location:

Change your redirects from:



window.location = "http://www.url.com/?customposttype=postslug";

And it should work properly.

  • Same thing. I noticed that if i put anything instead of that custom post type same thing happens. Like in the moment of redirection custom post type is not defined yet – raaaa Mar 19 '14 at 23:46

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.