Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[WordPress] How to add a Dynamic watermark on WordPress.

Posted on May 6, 2025May 6, 2025 By nim No Comments on [WordPress] How to add a Dynamic watermark on WordPress.

Bình thường thì bạn hay add watermark lên image nhưng nếu bạn muốn add 1 dynamic follow theo User name hoặc email của user đăng nhập thì như thế nào:

Nếu người dụng có quay phim màn hình thì sẽ thấy có user name của họ

Bạn sẽ cần tải lên 1 plugin là: Code Snippets

Sau khi cài xong thì bạn sẽ thêm code vào:

Sau đây là các code dynamic watermark bạn có thể thử từng cài và trải nghiệm

function add_custom_js() {
    ?>
    <script>
        // Mã JavaScript của bạn ở đây
        document.addEventListener('DOMContentLoaded', function() {
			const watermark = document.createElement('div');
			watermark.style.position = 'fixed';
			watermark.style.top = '0';
			watermark.style.left = '0';
			watermark.style.width = '100%';
			watermark.style.height = '100%';
			watermark.style.pointerEvents = 'none';
			watermark.style.zIndex = '9999';
			watermark.style.opacity = '0.1';
			watermark.style.fontFamily = 'Arial, sans-serif';
			watermark.style.fontSize = '14px';
			watermark.style.color = '#000';
			watermark.style.transform = 'rotate(-45deg)';
			watermark.style.display = 'flex';
			watermark.style.flexWrap = 'wrap';
			watermark.style.justifyContent = 'center';
			watermark.style.alignItems = 'center';
			watermark.style.overflow = 'hidden';
			watermark.textContent = 'User: ' + '<?php echo wp_get_current_user()->user_login; ?>';
			document.body.appendChild(watermark);
		});

    </script>
    <?php
}
add_action('wp_footer', 'add_custom_js');
function add_custom_js() {
    ?>
    <script>
        // Mã JavaScript của bạn ở đây
        document.addEventListener('DOMContentLoaded', function() {
			const watermark = document.createElement('div');
			watermark.style.position = 'fixed';
			watermark.style.top = '0';
			watermark.style.left = '0';
			watermark.style.width = '100%';
			watermark.style.height = '100%';
			watermark.style.pointerEvents = 'none';
			watermark.style.zIndex = '9999';
			watermark.style.opacity = '0.1';
			watermark.style.fontFamily = 'Arial, sans-serif';
			watermark.style.fontSize = '14px';
			watermark.style.color = '#000';
			watermark.style.transform = 'rotate(-45deg)';
			watermark.style.display = 'flex';
			watermark.style.flexWrap = 'wrap';
			watermark.style.justifyContent = 'center';
			watermark.style.alignItems = 'center';
			watermark.style.overflow = 'hidden';
			watermark.textContent = 'User: ' + '<?php echo wp_get_current_user()->user_login; ?>';
			// document.body.appendChild(watermark);
            // Sử dụng JavaScript để tạo nội dung watermark
            let textContent = 'User: ' + '<?php echo wp_get_current_user()->user_login; ?>';

            // Lặp lại văn bản nhiều lần để tạo thành các watermark
            let repeatedText = '';
            for (let i = 0; i < 100; i++) {  // Số lượng các watermark (có thể điều chỉnh tùy ý)
                repeatedText += textContent + ' ';
            }

            watermark.textContent = repeatedText.trim();
            document.body.appendChild(watermark);
		});

    </script>
    <?php
}
add_action('wp_footer', 'add_custom_js');
function add_custom_js() {
    ?>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const watermark = document.createElement('div');
            watermark.style.position = 'fixed';
            watermark.style.top = '0';
            watermark.style.left = '0';
            watermark.style.width = '100%';
            watermark.style.height = '100%';
            watermark.style.pointerEvents = 'none';
            watermark.style.zIndex = '9999';
            watermark.style.opacity = '0.1';
            watermark.style.fontFamily = 'Arial, sans-serif';
            watermark.style.fontSize = '14px';
            watermark.style.color = '#000';
            watermark.style.transform = 'rotate(-45deg)';
            watermark.style.display = 'flex';
            watermark.style.flexWrap = 'wrap';
            watermark.style.justifyContent = 'center';
            watermark.style.alignItems = 'center';
            watermark.style.overflow = 'hidden';
            watermark.textContent = 'User: ' + '<?php echo wp_get_current_user()->user_login; ?>';
            document.body.appendChild(watermark);

            // Thêm một biến để kiểm soát tốc độ di chuyển
            let lastMoveTime = Date.now();
            const moveInterval = 1000; // Thời gian giữa các lần di chuyển (ms)

            // Hàm tạo hiệu ứng di chuyển liên tục với tốc độ chậm hơn
            function moveWatermark() {
                const currentTime = Date.now();

                // Chỉ di chuyển nếu đã đủ thời gian trôi qua
                if (currentTime - lastMoveTime >= moveInterval) {
                    const x = Math.random() * window.innerWidth;  // Vị trí ngẫu nhiên trên trục X
                    const y = Math.random() * window.innerHeight; // Vị trí ngẫu nhiên trên trục Y
                    const rotate = Math.random() * 360;  // Góc xoay ngẫu nhiên từ 0 đến 360 độ

                    watermark.style.transform = `rotate(${rotate}deg)`;
                    watermark.style.left = `${x}px`;
                    watermark.style.top = `${y}px`;

                    lastMoveTime = currentTime; // Cập nhật thời gian di chuyển lần cuối
                }

                // Lặp lại liên tục nhưng có độ trễ
                requestAnimationFrame(moveWatermark);
            }

            // Bắt đầu di chuyển watermark liên tục
            moveWatermark();
        });
    </script>
    <?php
}
add_action('wp_footer', 'add_custom_js');
function add_custom_js() {
    ?>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const watermark = document.createElement('div');
            watermark.style.position = 'fixed';
            watermark.style.top = '0'; // Đặt watermark ở giữa chiều dọc màn hình
            watermark.style.left = '-200px'; // Đặt watermark bắt đầu ra ngoài màn hình bên trái
            watermark.style.width = '100%';
            watermark.style.height = '100%';
            watermark.style.pointerEvents = 'none';
            watermark.style.zIndex = '9999';
            watermark.style.opacity = '0.1';
            watermark.style.fontFamily = 'Arial, sans-serif';
            watermark.style.fontSize = '14px';
            watermark.style.color = '#000';
            watermark.style.transform = 'rotate(-45deg)';
            watermark.style.display = 'flex';
            watermark.style.flexWrap = 'wrap';
            watermark.style.justifyContent = 'center';
            watermark.style.alignItems = 'center';
            watermark.style.overflow = 'hidden';
            watermark.textContent = 'User: ' + '<?php echo wp_get_current_user()->user_login; ?>';
            document.body.appendChild(watermark);

            // Tốc độ di chuyển watermark
            let xPos = -200; // Bắt đầu từ ngoài màn hình bên trái
            let speed = 2;   // Tốc độ di chuyển

            // Hàm di chuyển watermark
            function moveWatermark() {
                xPos += speed; // Tăng dần giá trị X để di chuyển watermark

                // Khi watermark đi ra ngoài màn hình bên phải, reset lại về bên trái
                if (xPos > window.innerWidth) {
                    xPos = -200; // Đưa watermark lại ngoài màn hình bên trái
                }

                // Cập nhật vị trí của watermark
                watermark.style.left = `${xPos}px`;

                // Lặp lại liên tục với tốc độ mượt mà
                requestAnimationFrame(moveWatermark);
            }

            // Bắt đầu di chuyển watermark
            moveWatermark();
        });
    </script>
    <?php
}
add_action('wp_footer', 'add_custom_js');
Coding

Post navigation

Previous Post: [vnet/Azure] VNet provisioning via Terraform.
Next Post: [Azure] Insufficient regional vcpu quota left

More Related Articles

[Zeus] Retention Project Coding
[Popup/Ajax] Tạo popup(modal/bootstrap) insert data bằng ajax và php Coding
[redis-cli] a few Redis commands are useful. BareMetal
[Ajax/PHP] Cách để PHP trả Json Data về cho Ajax Coding
[Bootstrap] Hide and show elements by bootstrap. Coding
[web] Chuyển ảnh sang text Coding

Leave a Reply Cancel reply

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

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [WordPress] Hướng dấn gửi mail trên WordPress thông qua gmail. June 15, 2025
  • [Bitbucket] Git Clone/Pull/Push with Bitbucket through API Token. June 12, 2025
  • [Teamcity] How to transfer the value from pipeline A to pipeline B June 9, 2025
  • [Windows] Remove the process that consumes too much CPU. June 3, 2025
  • Deploying Web-Based File Managers: File Browser and KubeFileBrowser with Docker and Kubernetes June 3, 2025

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.