Wordpress

Copy the current page Url link button

Copy the current page Url link button

The code bellow, adds a “copy page URL” button, which is a convenient feature that allows users to quickly copy the link of the current web page they are viewing.

Here are some advantages:

  1. Time-saving: With the click of a button, users can quickly copy the page URL instead of having to manually highlight and copy the URL from the address bar. This can save several seconds for each copy operation.
  2. User convenience: Users can easily share or save the URL of a page without having to navigate to the address bar, which can be especially useful for longer URLs.
  3. Reduced errors: By eliminating the need to manually copy and paste URLs, the “copy page URL” button can help reduce errors caused by copying the wrong link or missing part of the URL.
    
function copy_link_button() { ?> <button id="copy-link-btn"><i class="fa fa-link"></i>Copy Link</button>; <script> const copyLinkBtn = document.getElementById('copy-link-btn'); copyLinkBtn.addEventListener('click', () => { // Copy the link const link = window.location.href; navigator.clipboard.writeText(link); // Change the icon to a green checkmark for 3 seconds const icon = copyLinkBtn.querySelector('i'); icon.classList.remove('fa-link'); icon.classList.add('fa-check', 'green'); setTimeout(() => { // Reset the icon after 3 seconds icon.classList.remove('fa-check', 'green'); icon.classList.add('fa-link'); }, 3000); }); </script> <?php } add_action( 'astra_entry_top', 'copy_link_button' );

Leave a Reply

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