Add a copy to clipboard button in WordPress elementor without a plugin

In this video I explain how to add WordPress copy to the clipboard button, click to copy text or code using a button. You can add a default WordPress editor or any kind of page builder like Elementor, Divi, etc.

In the tutorial, I am using Elementor page builder.

Download Elementor Page Builder:

Javascript Code Snippet:

<button onclick="copyText()">Copy all text to your clipboard!</button>

function copyText() {
  // Get the div element
  var divElement = document.getElementById("idtext");

  // Create a range object
  var range = document.createRange();

  // Select the contents of the div element

  // Add the range to the user's selection

  // Copy the selected text to the clipboard

  // Give a visual feedback to the user that the text has been copied
  alert("Text has been copied!");

If you face any issues or can’t implement it on your website contact me.