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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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: '[email protected]'
};
}
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();
}
</code>
<code>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: '[email protected]' }; } 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(); } </code>
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: '[email protected]'
    };
}

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.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật