How to Put a Timer on a Download Button in WordPress

One way to put a timer on a download button in WordPress is to use a plugin such as Countdown Timer Ultimate. After installing the plugin, create a new countdown timer and configure the settings to your liking. Then, add the timer shortcode to the page or post where your download button is located.

To add a timer to a download button specifically, you can use a plugin such as Buttonizer. This plugin allows you to create custom buttons and add various effects, including a countdown timer. After creating your custom download button, simply add the timer effect to the button in the Buttonizer settings. When the timer reaches zero, the button can be set to redirect to the download link.

How to Put a Timer on a Download Button in WordPress

How to Put a Timer on a Download Button in Manully CSS & Javascript

To put a timer on a download button manually using CSS and JavaScript, you can follow these general steps:

  1. First, create the HTML code for the download button, including the link to the file you want to download.
  2. Next, create the CSS code to style the button and add a countdown timer. You can use CSS to create a circular progress bar for the timer, and use keyframes to animate the timer based on the remaining time.
  3. Then, create the JavaScript code to calculate the remaining time and update the progress bar accordingly. You can use the setInterval() function to update the timer at regular intervals, and use the Date() object to calculate the remaining time.
  4. Finally, add event listeners to the button so that when the timer reaches zero, the button is disabled and the file is downloaded.

Here is a basic example of the code you might use:

CSS Code (For Head Tag):

    <style>
    /* countdown time redirect button css */
      #redirect-download{
        padding: 10px 25px 10px 25px; 
        border: none; 
        border-radius:5px;
        color: white; 
        background: dodgerblue; 
        font-weight: 600;
      }
      #redirect-download:hover{
      background:royalblue;
      }
    </style> 

JAVA Script (For Footer/Body Tag):

  <script>
        document.getElementById("post-Title").innerHTML = document.getElementById("postTitle").innerHTML;
        var postTitle = document.getElementById("postTitle").innerHTML;
        function redirectbtn(){
             localStorage.setItem("Post Title", postTitle)
             localStorage.setItem("Download Link",link);
             return false;
        }
    </script>

HTML Code for Posts:

<center>
    <!-- Google Adsense Code-->
         <h2 style="margin: 0px;">Download<span id="post-Title"></span></h2> 
          <form action="Page Download Link" target="_blank" style="margin-bottom: 15px;">
            <button id="redirect-download" onclick="redirectbtn();"><i class="fa fa-download"></i>  Download Now</button>
          </form>
         <!-- Google Adsense Code-->
</center>
<script>
    // download link paste here
      var link = "Download Link";
</script>

New Page Code:

    <center> 
     <!--Google Adsense Code-->
      <br>
    <center> 
      <style>#postTitle{text-align: center;}</style>  
        <button id="download-btn" onclick="generate()">
                  <i class="fa fa-download"></i> Download Now
              </button>
              <div id="refresh" style="display: none; font-size: 18px;"><b>Thanks!</b><br> Your download will start in few seconds... <br> If not then,</div>
              <a href="" id="re-download-btn" style="display: none;">Click Here</a>
              <script>
                  function generate() {
                      var j = document.getElementById("refresh");
                      var e, n = document.getElementById("re-download-btn"),
                          t = document.getElementById("download-btn"),
                          a = document.getElementById("re-download-btn").href,
                          l = 5,
                          d = document.createElement("span");
                      n.parentNode.replaceChild(d, n),
                          e = setInterval(function () {
                              --l < 0 ? (d.parentNode.replaceChild(n, d),
                                  clearInterval(e),
                                  window.location.replace(a),
                                  j.style.display = "contents",
                                  n.style.display = "inline") : (d.innerHTML = "<div class='waiting'>Please Wait...</div><div class='timer'>" + l.toString() + "</div> <div class='second'>Seconds</div>",
                                      t.style.display = "none")
                          }, 1e3)
                  }
              </script>
              <style>
                  button#download-btn {
                      padding: 10px 25px 10px 25px;
                      border: none;
                      border-radius: 5px;
                      color: white;
                      background: dodgerblue;
                      font-weight: 600;
                  }
                  button#download-btn:hover {
                      background: royalblue;
                  }
                  .timer {
                      background: bisque;
                      width: 5%;
                      padding: 10px;
                      font-size: 25px;
                      border-radius: 50%;
                      width: 7%;
                  }
              </style>
              <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"></link>  
          <script>
              document.getElementById("re-download-btn").href=localStorage.getItem("Download Link");
              document.getElementById("postTitle").innerHTML = localStorage.getItem("Post Title");
          </script>
      </center>
      <br><br>
    <!--Google Adsense Code-->
    </center>

Secand Method

HTML Code

<button id="download-btn">Download</button>

CSS

#download-btn {
  background-color: #4CAF50;
  color: white;
  padding: 10px 16px;
  font-size: 16px;
  border: none;
  cursor: pointer;
}

#download-btn:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

JavaScript

let downloadBtn = document.getElementById("download-btn");

downloadBtn.addEventListener("click", function() {
  // Disable the download button
  downloadBtn.disabled = true;

  // Start the timer
  let timeLeft = 10; // Set the time limit to 10 seconds
  let downloadTimer = setInterval(function() {
    timeLeft--;
    downloadBtn.innerHTML = "Download (" + timeLeft + ")";
    if (timeLeft <= 0) {
      clearInterval(downloadTimer);
      downloadBtn.innerHTML = "Download";
      downloadBtn.disabled = false;
    }
  }, 1000);

  // Simulate downloading
  setTimeout(function() {
    // Stop the timer
    clearInterval(downloadTimer);

    // Enable the download button
    downloadBtn.innerHTML = "Download";
    downloadBtn.disabled = false;

    // Trigger the download process
    // ...
  }, 10000); // Set the download time to 10 seconds
});

Conclusion

In conclusion, there are various ways to add a timer to a download button in WordPress or manually using CSS and JavaScript. Using plugins such as Countdown Timer Ultimate and Buttonizer can make the process easier and more streamlined, while manually coding the button using HTML, CSS, and JavaScript gives you more control over the customization and functionality of the button. Ultimately, the approach you choose will depend on your level of coding experience and the specific needs of your website or project.

Saurabh Vishwakarama is Founder & CEO of Techncigyan.com & Publisher with an Entrepreneur. He is Also a Student & Full Time Passionate Blogger.

Leave a Comment