Protect Content without Plugins Feature Image

If you’re looking to protect your content on WordPress without relying on multiple plugins, here’s an easy solution that only requires one lightweight plugin. Follow these steps:

How to Do It:

Install WPCode Lite:
WPCode Lite is a lightweight plugin that helps you manage code snippets without needing to install multiple small plugins. You can download it from the WordPress plugin repository or directly from our website.

Add Snippet:
Once WPCode Lite is installed, navigate to the “Code Snippets” section and click “Add New” to create a new snippet.

Copy the Code Below:
Replace the placeholder text “Protected Content. All rights reserved by Shawon Web.” with your own custom message. Then, paste this code into the snippet editor as a PHP snippet and activate it.

Clear Cache:
If you’re using a caching plugin, make sure to clear the cache after activating the snippet to ensure it takes effect immediately.

Enjoy Premium-Level Content Protection:
This method will provide robust protection similar to premium plugins, without the extra cost.

<?php
function add_content_protection() {
    ?>
    <style>
        .protected-content-message {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            padding: 20px;
            background-color: rgba(0,0,0,0.8);
            color: #fff;
            border-radius: 5px;
            z-index: 9999;
            text-align: center;
        }
        .show-message {
            display: block !important;
        }
        /* Disable text selection */
        body {
            -webkit-user-select: none; /* Safari */
            -moz-user-select: none;    /* Firefox */
            -ms-user-select: none;     /* Internet Explorer/Edge */
            user-select: none;         /* Non-prefixed version */
        }
        /* Obfuscate content */
        .obfuscate {
            visibility: hidden;
        }
    </style>
    <script>
        document.addEventListener("contextmenu", function(e) {
            e.preventDefault();
            showMessage();
        });

        document.addEventListener("keydown", function(e) {
            if (e.key === "F12" || 
                (e.ctrlKey && (e.key === "U" || e.key === "S" || e.key === "I")) || 
                (e.ctrlKey && e.shiftKey && e.key === "J")) {
                e.preventDefault();
                showMessage();
            }
        });

        document.addEventListener("mousedown", function(e) {
            if (e.button === 2) {
                e.preventDefault();
                showMessage();
            }
        });

        function showMessage() {
            var message = document.createElement("div");
            message.className = "protected-content-message show-message";
            message.innerHTML = "<p>Protected Content. All rights reserved by Shawon Web.</p>";
            document.body.appendChild(message);
            setTimeout(function() {
                message.remove();
            }, 3000);
        }

        // Detect Developer Tools
        (function() {
            const element = new Image();
            Object.defineProperty(element, 'id', {
                get: function() {
                    // Optionally redirect or show a warning
                    window.location = 'about:blank';
                }
            });
            console.log(element);
        })();

        // Detect if the page is being inspected using `console` methods
        (function() {
            const checkConsole = setInterval(function() {
                if (window.console && (console.firebug || (console.exception && console.table))) {
                    window.location = 'about:blank';
                }
            }, 1000);
        })();
    </script>
    <?php
}
add_action('wp_head', 'add_content_protection');

Final Step:

Activate the snippet from the top-right corner of the snippet editor. Your content is now protected!

Leave a Reply

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