THE SALE IS LIVE, GET ANY DESIGN AT 799 INR ONLY!

How to Protect Website Content From Being Copied

Code, Geek

How to protect website content from being copied: These new boys and girls create blogs quickly in the pursuit of earning money, as if they know everything.

But the reality is that they know only one way to copy the content of others and many times it happens that the content written by you gets copied by some other person or website, and the fruits of your hard work are snatched away from you.

In this article, I will tell you how to protect your website content from being copied. If you are a good blogger, then you know that the articles you write on your blog or website can be copied by someone, which means that someone can steal the content you have researched with great effort.

But wait, if you want, you can protect your blog content from being copied.

How to Protect Website Content From Being Copied

First of all, we need to understand why content is copied. People often try to increase traffic by publishing content written by others on their blog. This leads to duplicate content, and search engines recognize it and impose a penalty.

I want to tell you that there are some bloggers who instead of working hard, publish others’ posts on their website. This means that you work hard and someone else gets the credit.

So my advice is that neither do anything like this nor let anyone do it, but the problem is that you can stop yourself but how can others stop you, don’t worry, I am there for them. I will tell you how to protect the blog or website content from being copied?

If you are running your website on WordPress, then you can easily enable content protection by adding custom code. And if you are using Generatepress Pro Theme, then it is like icing on the cake.

With this, no other blogger will be able to touch your content nor will anyone be able to copy it, and even if someone copies it, see what will happen.

So let’s see how you can protect your content from being copied:

Method 1 : Adding multiple post links to the content being copied

The first trick is that whenever a content thief tries to steal your content, the link of your website will be copied along with that text. Not one, not two, but as many words as he copies, that many links will be copied along with that text. Isn’t it an amazing trick? Let me tell you how to do this:

First of all, if you are using Generatepress then start using Child Theme from today itself because it is very important to add custom code.

This means that you can add new functionality to your main theme without touching the main theme. Don’t worry, I will tell you for those who don’t use Generatepress.

For Generatepress Users

  • So for this we will use the “Hook” element of Generatepress.
  • So now first of all you have to go to your WordPress Dashboard and then go to Appearance > Elements > Add New Element and create a new hook.
  • After that copy this Javascript code given below and paste it in the empty box below.
  • Give any name to the hook so that you can identify later what this code was used for.
  • After that we will select the location of the hook as “wp_footer“. And in “Display Rules” we will select Posts & All Posts. And then we will Publish it.
  • If you guys want, you can also make the location Entire Site. I did Posts because what can anyone steal from the homepage and single pages of the site. The real fear is about the posts and by enabling it on Entire Site, it can also reduce the speed of the homepage a bit. So it is your choice what you want to do.
  • Now if you go and copy the site content and paste it somewhere, those content thieves will find it and they will leave it and run away. Meaning, in this code I have added a function so that whenever someone copies your content, the link of that post of yours should go after every copied word.
  • Those content thieves will get to see a scene like the image above. Meaning if 100 words are copied then a total of 100 links will be copied. Now copy 🤣!!! Only links in the name of content.
<script>
    // GeekDroid Copy Protection Script
    document.addEventListener('copy', function(e){
        var selectedText = window.getSelection().toString();
        var dynamicPageLink = document.location.href; // Dynamic URL of the current GeekDroid post
        var words = selectedText.split(' ');

        var modifiedWords = words.map(function(word) {
            return word + ' (Source: GeekDroid, URL: ' + dynamicPageLink + ')';
        });

        var modifiedText = modifiedWords.join(' ');

        e.clipboardData.setData('text', modifiedText);
        e.preventDefault();
    });
</script>

For Other Theme Users:

  • Other users will have to go to their cpanel/hpanel. And there they will have to access the file manager of the site. And a child theme is required for this or you can use a plugin like WPcode.
  • After that you have to go to PublicHTML > wp-content > Themes > your child theme directory.
  • Going inside it, you will have to create a new folder named JS and in it a new file named “copy-link.js“.
  • After that copy the above Javascript code and paste it in this copy-link.js file and save it. And remove the <script></script> tags from before and after the code.
  • We have just pasted this code, it will not do the work for which it is made. To make it work, we will have to enqueue it from our functions.php file, for that go to functions.php file, paste this code and save it.
function enqueue_geekdroid_scripts() {
    wp_enqueue_script('copy-link-script', get_stylesheet_directory_uri() . '/js/copy-link.js', array(), null, true );
}
add_action('wp_enqueue_scripts', 'enqueue_geekdroid_scripts');     
PHP
  • Now try refreshing the site and your work will be done.
  • You had to add this extra code because generatepres already has the hooks functionality to execute the Javascript, so it is a bit easier there.

Method 2 : Adding website link instead of the text

For Generatepress Users:

  • Generatepress Users same method as mentioned above. You have to create a new hook and paste this Javascript code there and give the location wp_footer and make the display rule Entire Site
<script>
    // Geekdroid Copy Protection Script
    document.addEventListener("copy", function(e) {
        // Fetch the text selected by the user
        var selectedText = window.getSelection().toString();

        // Verify if text got selected
        if (selectedText) {
            // Dynamically snag the post link; adjust your CSS selector as needed
            var postLink = document.querySelector(".post a"); 

            if (postLink) {
                // Craft a nifty span element carrying the link
                var invisibleSpan = document.createElement("span");
                invisibleSpan.style.position = "absolute";
                invisibleSpan.style.left = "-9999px";
                invisibleSpan.textContent = "(Geekdroid Source: " + postLink.href + ")";

                // Hook this invisible span onto the body
                document.body.appendChild(invisibleSpan);

                // Highlight the text inside our invisible span
                var range = document.createRange();
                range.selectNode(invisibleSpan);
                window.getSelection().removeAllRanges();
                window.getSelection().addRange(range);

                // Trigger a copy action, encapsulating the invisible link
                setTimeout(function() {
                    document.execCommand("copy");
                    window.getSelection().removeAllRanges();
                    // Vanish the invisible span post-copy
                    document.body.removeChild(invisibleSpan);
                }, 0);
            }
        }
    });
</script>
JavaScript
  • I have added a little text to give my brand name to the code invisiblespan.textcontent = “(geekdroid source: ” + postLink.href + “)”; meaning whenever someone copies the content then they will see my brand name along with the link to your site that who created this code. This will be a small favor from your side for my hard work.
  • If this doesn’t suit you and you want everything for free without giving credit to anyone, then you need to replace that line with this code: invisibleSpan.textContent = postLink.href; Now only the link of your site will be copied, not the content or any other text.

For Other Theme Users:

  • Other users will have to go to their cpanel/hpanel in the same way. And there they will have to access the file manager of the site. And follow the same process which I told for Other Theme Users in Method 1. As I told in Method 1, create a new file copy-link.js inside the js folder
  • All you need to do is remove the <script></script> tags before and after the above code and paste it into the new copy-link.js file.
  • After that, you have to insert the code of Method 1 given above in functions.php and save it so that you can enqueue the new JavaScript code from your functions.php file.

So now whenever someone tries to copy content from your site, instead of the content, they will only get the link to your post copied. Isn’t it useful? Let’s move on to the third method now.

Method 3 : Disabling Copy Function Site Wide

For Generatepress Users:

  • Generatepress Users have to create a hook and paste this Javascript code there and give the location “wp_head” and make the display rule Entire Site. The whole process is similar to Method 1
// Custom JavaScript Injection by GeekDroid
<body ondragstart="return false" onselectstart="return false" oncontextmenu="return false">
JavaScript

For Other Theme Users:

  • All you have to do is go to the file manager of your site and create a new JS file, then inside it create a JS file with the name geekdroid-disable-actions.js.
  • And paste this code in it.
// GeekDroid Disable Actions
jQuery(document).ready(function($) {
    $('body').attr({
        'ondragstart': 'return false',
        'onselectstart': 'return false',
        'oncontextmenu': 'return false'
    });
});
JavaScript
  • After that go to function.php and paste this code. So that you can enqueue that js file.
// GeekDroid Custom Script Enqueuer
function geekdroid_enqueue_custom_scripts() {
    wp_enqueue_script('geekdroid-disable-actions', get_stylesheet_directory_uri() . '/js/geekdroid-disable-actions.js', array('jquery'), null, true );
}
add_action('wp_enqueue_scripts', 'geekdroid_enqueue_custom_scripts');
PHP

Your work will be done. This function will disable text selection on your entire site and no text or image can be dragged on this page. What many people do is that they right click and go to Inspect Element and try to copy it through developer tools.

So now we have disabled the right click in this code and now no one will be able to right click.

Conclusion:

I hope you found my post today “How to protect blog or website content from being copied” quite useful. I have explained three ways in which you can protect your website content.

The first method is to add a link with every copied word, so that whoever copies the site content will get troubled by removing the link from the content.

Another way is to replace the content to be copied with a link to your site, this will also keep your content safe.

The third and most drastic method is to disable the copy function on the entire site. This method is for those who want to completely protect their content.

Finally, the most important thing is that you have to be a little more smart to protect your hard work. Avoid these copycats as much as possible, and protect your content with these new methods. And if you have any problem in implementing this, then you can ask in the comment box below, I will try my best to reply.

FAQs :

Can I use these methods together?

Yes, you can use a combination of these methods but this may impact the user experience as well.

Will these methods work for mobile users too?

Yes, these methods work well on most mobile phones too.

Will disabling the copy function on the site have any effect on SEO?

There is no direct impact, but user experience may deteriorate which can indirectly affect SEO.

Will these methods work on any CMS?

Yes, you can also use them on CMS like WordPress, Joomla, or Drupal.

Do I need to know coding to implement these methods?

Basic coding knowledge is required, but I have explained step by step in the post so that anyone can understand it easily.

Are the methods mentioned here 100% foolproof?

No, no security system is 100% foolproof, but these methods will prevent content theft by copying.

Leave a Comment

Item added to cart.
0 items - 0.00