0

is it possible to create a redirect only after the page has been scrooled, for example, in the middle and redirects to another page? I tried various solutions and plugins but couldn't find anything that suited me

1
  • Also this is not good for user experience or accessibility to randomly redirect a user as their scrolling, it will confuse screen readers.
    – wpDev
    Commented Mar 7, 2022 at 15:47

1 Answer 1

0

Try this solution: You can easily do this by using jQuery.

jQuery(document).scroll(function() {
  var y = $(this).scrollTop();
  if (y > 800) {
    window.location.replace("http://stackoverflow.com");
  } else {
    console.log('test');
  }
});
4
  • how do i put it in a WordPress page editor? Commented Mar 4, 2022 at 20:06
  • Just put this in the footer.php before the </footer> closing tag Commented Mar 4, 2022 at 20:42
  • if I put it in the footer all the pages will have the redirect, I have to do it only for a specific page and above all there must be this redirect after I have reached the middle of the page with the scroll Commented Mar 5, 2022 at 11:30
  • You can use the "page id" or is_page function and under that you can put the script. Commented Mar 7, 2022 at 14:49

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.