How to create WP JS redirect for an anchor tag

[ad_1]

Hi everyone!
This is very stupid, but I must redirect an anchor tag to another page.

**Q1** Is that even possible?

**Q2** Is it secure?

**Q3** How do I go about it?

Okay, so here’s what is happening…we redid our website, and in the previous version we had a form on a section of the homepage, and I had created an anchor tag to drive conversations; I also used the same anchor link on a printed bookmark for distribution. Now, with the new site, the anchor tag and the sections both don’t exist; instead, the form is on another page. We are running campaigns, and I need help fixing this.

Using redirection plugins doesn’t work since they operate on the server level, and anchor stage are client side.

I even tried redirection using .htaccess.

old link: [domain.com/#form])

New link: domain.com/pledge-form

[ad_2]
1 Comment
  1. You want to read incoming request, parse it for the #form hash link, and redirect that request to the new URL?

    I think this is impossible via PHP, here is a thread about it:

    You can detect a hash in javascript and you can forward the browser via javascript.. it’s not exactly ideal… but what is? You can do it a one-liner:

    <script>
    if (window.location.hash === “#form”) window.location.href = “/next.html”
    </script>

    just replace /next.html with your new URL and try and put this as close to the start of your <head> tag on your homepage. It should only run when it loads, so if you link to something with #form later it wont detect and redirect, since it has already fired.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer