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>
<script>
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
range.selectNode(divElement);
// Add the range to the user's selection
window.getSelection().addRange(range);
// Copy the selected text to the clipboard
document.execCommand("copy");
// Give a visual feedback to the user that the text has been copied
alert("Text has been copied!");
}
</script>
If you face any issues or can’t implement it on your website contact me.