Adding Dynamic User-Specific Watermark to WordPress Site

I'm trying to implement a dynamic watermark on my WordPress site to deter content misuse. The watermark should display the logged-in user's username and email across the entire page. I'm using the Code Snippets plugin to add custom JavaScript. Here's the code I've implemented: javascriptCopy// Function to create watermark function createWatermark(text) { const watermark = document.createElement('div'); watermark.className = 'dynamic-watermark'; watermark.style.cssText = ` position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 9999; opacity: 0.1; font-family: Arial, sans-serif; font-size: 14px; color: #000; transform: rotate(-45deg); display: flex; flex-wrap: wrap; justify-content: center; align-items: center; overflow: hidden; `; Create multiple instances of the text for (let i = 0; i < 15; i++) { const span = document.createElement('span'); span.textContent = text; span.style.cssText = ` margin: 20px; white-space: nowrap; `; watermark.appendChild(span); } document.body.appendChild(watermark); } Function to get user data(placeholder) function getUserData() { This is where I need help return { username: 'example_user', email: 'user@example.com' }; } Main function to add watermark function addWatermark() { const userData = getUserData(); const watermarkText = `${userData.username} | ${userData.email}`; createWatermark(watermarkText); } Run the watermark function when the page is loaded if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', addWatermark); else { addWatermark(); } The watermark is not appearing on the site, and I'm not sure how to correctly retrieve the logged-in user's information in WordPress to use in the JavaScript. How can I modify the getUserData() function to correctly retrieve the current logged-in user's username and email in WordPress? Are there any potential issues with my current approach that could be preventing the watermark from appearing? Now users are taking screenshots of my website content and they are misusing it. i want to set a watermark text on my website like 10 to 15 times repeated, but the water mark must be user username and email so if anyone is using my website so his username and email will be shown as water mark. i want to achieve this in wordpress.

Comment (0)

You’ll be in good company