WordPress permalinks and javascript redirection

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:

Read More
window.location.replace(encodeURIComponent("http://www.url.com/customposttype/postslug"));

default permalinks structure script:

window.location.replace(encodeURIComponent("http://www.url.com/?customposttype=postslug"))

Related posts

Leave a Reply

1 comment

  1. 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.replace(encodeURIComponent("http://www.url.com/?customposttype=postslug"))
    

    to

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

    And it should work properly.