how to create back button with html code for wordpress website

Back always

<button onclick="goBack()"> < Back to BlogsTour</button>

<script>
  function goBack() {
    window.history.back();
  }
</script>

Always Back + if there is no History Back to my Url (blogstour.com)

<button onclick="goBack()"> &lt; Back to BlogsTour</button>

<script>
  function goBack() {
    // Check if there's a history to go back to
    if (window.history.length > 1) {
      // If there is, go back in history
      window.history.back();
    } else {
      // If there's no history, redirect to the specified link
      window.location.href = 'https://blogstour.com';
    }
  }
</script>

Leave a Comment

Your email address will not be published. Required fields are marked *