• On the home page I would like to replace the post URL for another. I wrote the script:

    function myFunction() {
      var x = document.querySelectorAll('a[href="https://www.freuciv.com/2020/02/10/wozu-brauchen-sie-die-weinreste-geheimnisse-der-gastronomiebranche/"]');
      var i;
      for (i = 0; i < x.length; i++) {
        x[i].href = "https://www.freuciv.com/?fwp_typ=geheimnisse-der-gastronomiebranche&fwp_sort=title_asc&hideParent";
      }
    }
    
    myFunction()

    (Why do I need it? Look at the URL of the first featured post: “Wozu brauchen sie die Weinreste? Geheimnisse der Gastronomiebranche.” It doesn’t lead to any post, but to search results. In this case, the book chapters are searched: Chapter 1, 2, 3…)

    Everything works, but there is a problem. When I click the “load more” button, which loads more posts, the script must be run again. So I assigned (for now in the console) this function to the button, but it runs before the posts appear.

    document.querySelector("#load-more-button button").addEventListener("click", myFunction);

    It could run with a delay, but this solution seems to be very inelegant, doesn’t it? But there is another problem: after running the function disappears from the button. What should I do to keep it there?

    So how better to solve this problem? Is there any clever way to replace the selected post URL with another?

    • This topic was modified 6 years, 5 months ago by reti.
    • This topic was modified 6 years, 5 months ago by reti.
    • This topic was modified 6 years, 5 months ago by reti.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Are you wanting to redirect the featured post to a search page, and not to a post? Is that your final objective?

    In that case, it may be good to use a redirect plugin which redirects the URL of the post to any other destination URL that you need.

    You may find some redirect plugins here :
    https://wordpress.org/plugins/search/redirect/

    (check description, frequency of updation, and reviews. Evaluate before using)

    Thread Starter reti

    (@reti)

    Thank you very much! You’ve helped me a lot. This solution is very good.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘how to replace the selected post URL with another?’ is closed to new replies.